Class: DataModeler::Dataset::Accessor
- Inherits:
-
Object
- Object
- DataModeler::Dataset::Accessor
- Includes:
- ConvertingTimeAndIndices, IteratingBasedOnNext
- Defined in:
- lib/data_modeler/dataset/accessor.rb
Overview
Build complex inputs and targets from the data to train the model.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#end_idx ⇒ Object
readonly
Returns the value of attribute end_idx.
-
#first_idx ⇒ Object
readonly
Returns the value of attribute first_idx.
-
#input_idxs ⇒ Object
readonly
Returns the value of attribute input_idxs.
-
#input_series ⇒ Object
readonly
Returns the value of attribute input_series.
-
#look_ahead ⇒ Object
readonly
Returns the value of attribute look_ahead.
-
#ninput_points ⇒ Object
readonly
Returns the value of attribute ninput_points.
-
#nrows ⇒ Object
readonly
Returns the value of attribute nrows.
-
#target_idx ⇒ Object
readonly
Returns the value of attribute target_idx.
-
#target_series ⇒ Object
readonly
Returns the value of attribute target_series.
-
#tspread ⇒ Object
readonly
Returns the value of attribute tspread.
Instance Method Summary collapse
-
#==(other) ⇒ true|false
Equality operator – most useful in testing.
-
#initialize(data, inputs:, targets:, first_idx:, end_idx:, ninput_points:, tspread:, look_ahead:) ⇒ Accessor
constructor
A new instance of Accessor.
-
#inputs ⇒ Array
Builds inputs for the model.
-
#next ⇒ Array
Returns the next pair [inputs, targets] and increments the target.
-
#peek ⇒ Array
Returns the next pair [inputs, targets].
-
#targets ⇒ Array
Builds targets for the model.
-
#trg_time ⇒ type of `data[:time]`
Returns the time of the current target.
-
#values ⇒ Array<Array>
Compatibility with Hash, which returns a list of series’ data arrays.
Methods included from ConvertingTimeAndIndices
Methods included from IteratingBasedOnNext
Constructor Details
#initialize(data, inputs:, targets:, first_idx:, end_idx:, ninput_points:, tspread:, look_ahead:) ⇒ Accessor
we expect Datasets indices to be used with left inclusion but right exclusion, i.e. targets are considered in the range ‘[from,to)`
Returns a new instance of Accessor.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/data_modeler/dataset/accessor.rb', line 26 def initialize data, inputs:, targets:, first_idx:, end_idx:, ninput_points:, tspread:, look_ahead: @data = data @input_series = inputs @target_series = targets @first_idx = first_idx @end_idx = end_idx @ninput_points = ninput_points @nrows = data[:time].size @tspread = tspread @look_ahead = look_ahead @first_idx = first_idx reset_iteration end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/data_modeler/dataset/accessor.rb', line 5 def data @data end |
#end_idx ⇒ Object (readonly)
Returns the value of attribute end_idx.
5 6 7 |
# File 'lib/data_modeler/dataset/accessor.rb', line 5 def end_idx @end_idx end |
#first_idx ⇒ Object (readonly)
Returns the value of attribute first_idx.
5 6 7 |
# File 'lib/data_modeler/dataset/accessor.rb', line 5 def first_idx @first_idx end |
#input_idxs ⇒ Object (readonly)
Returns the value of attribute input_idxs.
5 6 7 |
# File 'lib/data_modeler/dataset/accessor.rb', line 5 def input_idxs @input_idxs end |
#input_series ⇒ Object (readonly)
Returns the value of attribute input_series.
5 6 7 |
# File 'lib/data_modeler/dataset/accessor.rb', line 5 def input_series @input_series end |
#look_ahead ⇒ Object (readonly)
Returns the value of attribute look_ahead.
5 6 7 |
# File 'lib/data_modeler/dataset/accessor.rb', line 5 def look_ahead @look_ahead end |
#ninput_points ⇒ Object (readonly)
Returns the value of attribute ninput_points.
5 6 7 |
# File 'lib/data_modeler/dataset/accessor.rb', line 5 def ninput_points @ninput_points end |
#nrows ⇒ Object (readonly)
Returns the value of attribute nrows.
5 6 7 |
# File 'lib/data_modeler/dataset/accessor.rb', line 5 def nrows @nrows end |
#target_idx ⇒ Object (readonly)
Returns the value of attribute target_idx.
5 6 7 |
# File 'lib/data_modeler/dataset/accessor.rb', line 5 def target_idx @target_idx end |
#target_series ⇒ Object (readonly)
Returns the value of attribute target_series.
5 6 7 |
# File 'lib/data_modeler/dataset/accessor.rb', line 5 def target_series @target_series end |
#tspread ⇒ Object (readonly)
Returns the value of attribute tspread.
5 6 7 |
# File 'lib/data_modeler/dataset/accessor.rb', line 5 def tspread @tspread end |
Instance Method Details
#==(other) ⇒ true|false
Equality operator – most useful in testing
99 100 101 102 103 104 105 |
# File 'lib/data_modeler/dataset/accessor.rb', line 99 def == other self.class == other.class && # terminate check here if wrong class data.object_id == other.data.object_id && # both `data` point to same object (instance_variables - [:@data]).all? do |var| self.instance_variable_get(var) == other.instance_variable_get(var) end end |
#inputs ⇒ Array
Builds inputs for the model
44 45 46 47 48 49 50 |
# File 'lib/data_modeler/dataset/accessor.rb', line 44 def inputs input_idxs.flat_map do |idx| input_series.collect do |s| data[s][idx] end end end |
#next ⇒ Array
Returns the next pair [inputs, targets] and increments the target
78 79 80 81 82 83 |
# File 'lib/data_modeler/dataset/accessor.rb', line 78 def next peek.tap do @target_idx += 1 @input_idxs = init_inputs end end |
#peek ⇒ Array
Returns the next pair [inputs, targets]
71 72 73 74 |
# File 'lib/data_modeler/dataset/accessor.rb', line 71 def peek raise StopIteration if target_idx >= end_idx [trg_time, inputs, targets] end |
#targets ⇒ Array
Builds targets for the model
54 55 56 57 58 |
# File 'lib/data_modeler/dataset/accessor.rb', line 54 def targets target_series.collect do |s| data[s][target_idx] end end |
#trg_time ⇒ type of `data[:time]`
Returns the time of the current target
62 63 64 |
# File 'lib/data_modeler/dataset/accessor.rb', line 62 def trg_time data[:time][target_idx] end |
#values ⇒ Array<Array>
Compatibility with Hash, which returns a list of series’ data arrays
92 93 94 |
# File 'lib/data_modeler/dataset/accessor.rb', line 92 def values to_a.transpose end |