y_petri 2.1.31 → 2.1.33

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c98edfb8140dbc62e7012bd0ce4d25978451e22
4
- data.tar.gz: 6c3d695901347b8bf8deac87999bc588c21ed503
3
+ metadata.gz: 43e532fceaec5c32c5ee7ca4364a2165f134d94f
4
+ data.tar.gz: 2ca12cc72e7f7372d513eaccea15f024a6eda626
5
5
  SHA512:
6
- metadata.gz: 78e6c1c2aa034e7e893411600381d3e4bad5cd4ec3e5a12f5dbc1a10fb938d7c90c0258a252474391b7f3092994f8b6b28e74bc17c26d61c8a6d7721871e30c6
7
- data.tar.gz: bec532ac1b9c25649a75e34d6e7806a774d231e6cdefc990c555559324ebc92a98cc460ac28004bba5f3f357a66a9191fcf1475c76c272ac26caaff20fb43997
6
+ metadata.gz: ab51a968eeb6c30f87d5f12dba00311a32e5bb6042ba0cc8a4d638cdecf352294a32da4dd5737f96f4a3da8220801d858a8cd4b120792f2837124edd9592b549
7
+ data.tar.gz: 2f4e63e8c7d3ec1d619b8685886bc66cba4a899b46c4ac69f6ca6929df878110e6015970d3b0cc99e696d2b4f994d5855029cc913ba04b05d6ce05bb992e0665
@@ -107,7 +107,9 @@ module YPetri::Agent::SimulationRelated
107
107
  :initial_marking_cc, :simulation_settings_cc,
108
108
  to: :world
109
109
 
110
- delegate :pm, to: :simulation
110
+ delegate :pm,
111
+ :recording,
112
+ to: :simulation
111
113
 
112
114
  # Pretty print the state.
113
115
  #
data/lib/y_petri/dsl.rb CHANGED
@@ -42,6 +42,8 @@ module YPetri
42
42
  :clamp_cc, :initial_marking_cc, :simulation_settings_cc,
43
43
  :simulation_point_position,
44
44
  :simulation,
45
+ :pm, # deleg. to simulation
46
+ :recording, # deleg. to simulation
45
47
  :clamp_collection, :cc,
46
48
  :initial_marking_collection, :imc,
47
49
  :simulation_settings_collection, :ssc,
@@ -41,12 +41,32 @@ class YPetri::Net::DataSet < Hash
41
41
  type == :timed
42
42
  end
43
43
 
44
- # Returns a Record instance corresponding to the given recorded event.
44
+ # Returns the Record instance corresponding to the given recorded event.
45
45
  #
46
46
  def record( event )
47
47
  features.load( fetch event )
48
48
  end
49
49
 
50
+ # Returns the nearest event smaller or equal to the supplied event-type
51
+ # argument. The second optional ordered argument, true by default, controls
52
+ # whether equality is accepted. If set to false, then the nearest _smaller_
53
+ # event is sought.
54
+ #
55
+ def floor( event, equal_ok=true )
56
+ e = events.ascending_floor( event, equal_ok )
57
+ e.nil? ? nil : e
58
+ end
59
+
60
+ # Returns the nearest event greater or equal to the supplied event-type
61
+ # argument. The second optional ordered argument, true by default, controls
62
+ # whether equality is accepted. If set to false, then the nearest _greater_
63
+ # event is sought.
64
+ #
65
+ def ceiling( event, equal_ok=true )
66
+ e = events.ascending_ceiling( event, equal_ok )
67
+ e.nil? ? nil : e
68
+ end
69
+
50
70
  # Revives records from values.
51
71
  #
52
72
  def records
@@ -69,18 +89,49 @@ class YPetri::Net::DataSet < Hash
69
89
  # Record class instance.
70
90
  #
71
91
  def interpolate( event )
72
- # TODO: This whole interpolation thing is unfinished.
73
92
  begin
74
93
  record( event )
75
94
  rescue KeyError => msg
76
- timed? or raise TypeError, "Event #{event} does not have a record! (%s)" %
95
+ timed? or raise TypeError, "Event #{event} not recorded! (%s)" %
77
96
  "simulation type: #{type.nil? ? 'nil' : type}"
78
- f_time, floor = floor( event ) # timed datasets support floor, ceiling
79
- c_time, ceiling = ceiling( time )
80
- floor + ( ceiling - floor ) / ( c_time - f_time ) * ( time - f_time )
97
+ # (Remark: #floor, #ceiling supported by timed datasets only)
98
+ fe = floor( event )
99
+ fail "Event #{event} has no floor!" if fe.nil?
100
+ f = Matrix.column_vector record( fe )
101
+ ce = ceiling( event )
102
+ fail "Event #{event} has no ceiling!" if ce.nil?
103
+ c = Matrix.column_vector record( ce )
104
+ rslt = f + ( c - f ) / ( ce - fe ) * ( event - fe )
105
+ features.load( rslt.column_to_a )
81
106
  end
82
107
  end
83
108
 
109
+ # Resamples the recording.
110
+ #
111
+ def resample **nn
112
+ time_range = nn.may_have( :time_range, syn!: :time ) ||
113
+ events.first .. events.last
114
+ sampling = nn.must_have :sampling
115
+ t0, target_time = time_range.begin, time_range.end
116
+ t = t0
117
+ loop.with_object self.class.new do |o|
118
+ o.update t => interpolate( t )
119
+ t += sampling
120
+ return o if t > target_time
121
+ end
122
+ end
123
+
124
+ # Computes the distance to another dataset.
125
+ #
126
+ def distance( other )
127
+ sum_of_sq = events
128
+ .map { |e| [ e, other.interpolate( e ) ] }
129
+ .map { |rec1, rec2| rec1.euclidean_distance rec2 }
130
+ .map { |dist| dist * dist }
131
+ .reduce( :+ )
132
+ sum_of_sq ** 0.5
133
+ end
134
+
84
135
  # Returns the data series for the specified features.
85
136
  #
86
137
  def series arg=nil
@@ -162,4 +162,12 @@ class YPetri::Net::State::Features::Record < Array
162
162
  end
163
163
  end
164
164
  end
165
+
166
+ # Computes the Euclidean distance from another record.
167
+ #
168
+ def euclidean_distance other
169
+ sum_of_sq = features.map { |f|
170
+ fetch( f ) - other.fetch( f )
171
+ }.map { |dist| dist * dist }.reduce( :+ )
172
+ end
165
173
  end # class YPetri::Net::State::Features::Record
@@ -97,7 +97,7 @@ class YPetri::Simulation
97
97
  m = settings[:marking]
98
98
  init_m = settings[:initial_marking] || {}
99
99
  use_default_marking = if settings.has? :use_default_marking then
100
- settings[:use_default_marking]
100
+ settings[ :use_default_marking ]
101
101
  else true end
102
102
  # Time-independent simulation settings received, constructing param. classes
103
103
  param_class!( { Place: PlaceRepresentation,
@@ -1,4 +1,4 @@
1
1
  module YPetri
2
- VERSION = "2.1.31"
2
+ VERSION = "2.1.33"
3
3
  DEBUG = false
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: y_petri
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.31
4
+ version: 2.1.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - boris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-20 00:00:00.000000000 Z
11
+ date: 2013-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: y_support