data_modeler 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 173d569d4d705b32ca166d444766651f94b4a98d
4
- data.tar.gz: ec61342d6188533751c874549c6f55d346d02bcb
3
+ metadata.gz: fb390503600e0270198476fd58e28fbeb7875b53
4
+ data.tar.gz: 5c57a5bdb492a069f4bfc6ffbec65b513fb94e82
5
5
  SHA512:
6
- metadata.gz: 3cb220eeb8f7349321d35adb07efe919c9a23e9e0fe0459ca411b87632dd89ce21a7e1e04d350f1527e9e0f83b9924445b2c155c6af8fb9b71caace5b2600301
7
- data.tar.gz: 74c46dea839cf5c1f99346ae197b7c87d06815c1d8c1e3c61238fac0801b6e20dd288efbaf7026f2a5991052c823a0179f48054473cbce4a628b5ff74f8b198d
6
+ metadata.gz: 1e951667d4207d4293ee9666ed786886528c496e272ea71e7ba7a885780ac5b84e2724f00d3beb97b5f143babe467c19881f3dd0014a4132816bc7e4188da734
7
+ data.tar.gz: d1b0bcc66cb30693d65370409d129a5102a9dfb6e65afca11be98efc125ba3b0c85df546feb01f2f5857445259cf441c9c7c60b150cda239ec6e5bc47c3a662e
@@ -1,3 +1,6 @@
1
+ require 'pathname'
2
+ require 'fileutils'
3
+
1
4
  require "data_modeler/support"
2
5
 
3
6
  # Dataset
@@ -42,9 +42,9 @@ class DataModeler::Base
42
42
  end
43
43
  model.reset
44
44
  model.train train_set, report_interval: report_interval
45
- test_input, observations = tset_gen.test(nrun).values
45
+ times, test_input, observations = tset_gen.test(nrun).values
46
46
  predictions = model.test test_input
47
- save_run nrun, model, [predictions, observations]
47
+ save_run nrun, model, [times, predictions, observations]
48
48
  end
49
49
  end
50
50
 
@@ -121,12 +121,12 @@ class DataModeler::Base
121
121
  # @param predobs [Array<Array<pred, obs>>] list of prediction-observation pairs
122
122
  # @return [void]
123
123
  # @note side effect: saves model and predobs to file system
124
- def save_run nrun, model, predobs
124
+ def save_run nrun, model, tpredobs
125
125
  run_id = format '%02d', nrun
126
126
  model.save out_dir.join("model_#{run_id}.sav") if save_models?
127
- CSV.open(out_dir.join("predobs_#{run_id}.csv"), 'wb') do |csv|
128
- csv << targets.collect { |t| ["p_#{t}", "o_#{t}"] }.transpose.flatten
129
- predobs.transpose.each { |po| csv << po.flatten }
127
+ CSV.open(out_dir.join("tpredobs_#{run_id}.csv"), 'wb') do |csv|
128
+ csv << (%w(time) + targets.collect { |t| ["p_#{t}", "o_#{t}"] }.transpose.flatten)
129
+ tpredobs.transpose.each { |tpo| csv << tpo.flatten }
130
130
  end
131
131
  end
132
132
  end
@@ -38,8 +38,6 @@ class DataModeler::Dataset
38
38
  end
39
39
 
40
40
  # TODO: make sure constructor requirements are unnecessary for static models
41
- # TODO: check if enough data / minimum_target
42
- # TODO: the check in `#init_target` should go in the `ds_gen`
43
41
 
44
42
  # Builds inputs for the model
45
43
  # @return [Array]
@@ -59,6 +57,12 @@ class DataModeler::Dataset
59
57
  end
60
58
  end
61
59
 
60
+ # Returns the time of the current target
61
+ # @return [type of `data[:time]`]
62
+ def trg_time
63
+ data[:time][target_idx]
64
+ end
65
+
62
66
  ### ITERATION
63
67
 
64
68
  # Returns the next pair [inputs, targets]
@@ -66,7 +70,7 @@ class DataModeler::Dataset
66
70
  # @raise [StopIteration] when the target index is past the dataset limits
67
71
  def peek
68
72
  raise StopIteration if target_idx >= end_idx
69
- [inputs, targets]
73
+ [trg_time, inputs, targets]
70
74
  end
71
75
 
72
76
  # Returns the next pair [inputs, targets] and increments the target
@@ -54,7 +54,7 @@ class DataModeler::Models::FANN
54
54
  report_interval: report_interval, desired_error: desired_error)
55
55
  end
56
56
  # TODO: optimize maybe?
57
- inputs, targets = trainset.values
57
+ times, inputs, targets = trainset.values
58
58
  tset = RubyFann::TrainData.new inputs: inputs, desired_outputs: targets
59
59
  # fann.init_weights tset # test this weights initialization
60
60
 
@@ -73,7 +73,7 @@ class DataModeler::Models::FANN
73
73
  # check to improve performance
74
74
  fann.randomize_weights(*init_weights_range.map(&method(:Float)))
75
75
  # test it on inputs
76
- inputs, targets = trainset.values
76
+ times, inputs, targets = trainset.values
77
77
  outputs = test(inputs)
78
78
  # calculate RMSE
79
79
  rmse_fn = -> (outs) do
@@ -99,7 +99,7 @@ class DataModeler::Models::FANN
99
99
  # @param inputs [Array<Array<inputs>>] sequence of inputs for the model
100
100
  # @return [Array<Array<outputs>>] outputs corresponding to each input
101
101
  def test inputs
102
- inputs.collect { |i| fann.run i }
102
+ inputs.collect &fann.method(:run)
103
103
  end
104
104
 
105
105
  # Saves the model
@@ -5,7 +5,7 @@ module DataModeler
5
5
  ### VERSION
6
6
 
7
7
  # Version number
8
- VERSION = "0.3.3"
8
+ VERSION = "0.3.4"
9
9
 
10
10
  ### HELPER FUNCTIONS
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_modeler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giuseppe Cuccu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-18 00:00:00.000000000 Z
11
+ date: 2017-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-fann