Class: DataModeler::Dataset
- Inherits:
-
Object
- Object
- DataModeler::Dataset
- Includes:
- ConvertingTimeAndIndices, IteratingBasedOnNext
- Defined in:
- lib/data_modeler/dataset/dataset.rb,
lib/data_modeler/exceptions.rb
Overview
checks to validate if enough data is present (given ntimes, tspread and look_ahead) should be done on the caller (typically DatasetGen)
Build complex inputs and targets from the data to train the model.
Defined Under Namespace
Classes: TimeNotFoundError
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.
-
#nrows ⇒ Object
readonly
Returns the value of attribute nrows.
-
#ntimes ⇒ Object
readonly
Returns the value of attribute ntimes.
-
#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) ⇒ void
Overloaded comparison for easier testing.
-
#initialize(data, inputs:, targets:, first_idx:, end_idx:, ntimes:, tspread:, look_ahead:) ⇒ Dataset
constructor
A new instance of Dataset.
-
#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.
Methods included from ConvertingTimeAndIndices
Methods included from IteratingBasedOnNext
Constructor Details
#initialize(data, inputs:, targets:, first_idx:, end_idx:, ntimes:, tspread:, look_ahead:) ⇒ Dataset
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 Dataset.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/data_modeler/dataset/dataset.rb', line 29 def initialize data, inputs:, targets:, first_idx:, end_idx:, ntimes:, tspread:, look_ahead: @data = data @input_series = inputs @target_series = targets @first_idx = first_idx @end_idx = end_idx @ntimes = ntimes @nrows = data[:time].size @tspread = tspread @look_ahead = look_ahead @target_idx = first_idx @input_idxs = init_inputs end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/data_modeler/dataset/dataset.rb', line 8 def data @data end |
#end_idx ⇒ Object (readonly)
Returns the value of attribute end_idx.
8 9 10 |
# File 'lib/data_modeler/dataset/dataset.rb', line 8 def end_idx @end_idx end |
#first_idx ⇒ Object (readonly)
Returns the value of attribute first_idx.
8 9 10 |
# File 'lib/data_modeler/dataset/dataset.rb', line 8 def first_idx @first_idx end |
#input_idxs ⇒ Object (readonly)
Returns the value of attribute input_idxs.
8 9 10 |
# File 'lib/data_modeler/dataset/dataset.rb', line 8 def input_idxs @input_idxs end |
#input_series ⇒ Object (readonly)
Returns the value of attribute input_series.
8 9 10 |
# File 'lib/data_modeler/dataset/dataset.rb', line 8 def input_series @input_series end |
#look_ahead ⇒ Object (readonly)
Returns the value of attribute look_ahead.
8 9 10 |
# File 'lib/data_modeler/dataset/dataset.rb', line 8 def look_ahead @look_ahead end |
#nrows ⇒ Object (readonly)
Returns the value of attribute nrows.
8 9 10 |
# File 'lib/data_modeler/dataset/dataset.rb', line 8 def nrows @nrows end |
#ntimes ⇒ Object (readonly)
Returns the value of attribute ntimes.
8 9 10 |
# File 'lib/data_modeler/dataset/dataset.rb', line 8 def ntimes @ntimes end |
#target_idx ⇒ Object (readonly)
Returns the value of attribute target_idx.
8 9 10 |
# File 'lib/data_modeler/dataset/dataset.rb', line 8 def target_idx @target_idx end |
#target_series ⇒ Object (readonly)
Returns the value of attribute target_series.
8 9 10 |
# File 'lib/data_modeler/dataset/dataset.rb', line 8 def target_series @target_series end |
#tspread ⇒ Object (readonly)
Returns the value of attribute tspread.
8 9 10 |
# File 'lib/data_modeler/dataset/dataset.rb', line 8 def tspread @tspread end |
Instance Method Details
#==(other) ⇒ void
This method returns an undefined value.
Overloaded comparison for easier testing
87 88 89 90 91 92 93 |
# File 'lib/data_modeler/dataset/dataset.rb', line 87 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
50 51 52 53 54 55 56 |
# File 'lib/data_modeler/dataset/dataset.rb', line 50 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
75 76 77 78 79 80 |
# File 'lib/data_modeler/dataset/dataset.rb', line 75 def next peek.tap do @target_idx += 1 @input_idxs = init_inputs end end |
#peek ⇒ Array
Returns the next pair [inputs, targets]
68 69 70 71 |
# File 'lib/data_modeler/dataset/dataset.rb', line 68 def peek raise StopIteration if target_idx >= end_idx [inputs, targets] end |
#targets ⇒ Array
Builds targets for the model
60 61 62 63 64 |
# File 'lib/data_modeler/dataset/dataset.rb', line 60 def targets target_series.collect do |s| data[s][target_idx] end end |