data_modeler 0.2.0 → 0.2.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 023a9053513981d2058cd23f7b0a9154da588b6b
|
4
|
+
data.tar.gz: 5e7a9c83204a2da747aa273e1ced42b4d1fefe36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70cbccdd7cd7c9a70142c853f2a68e2a9be28412b05c48d6cd0b0440b703d6f878cdb58b1b0902efab321b4064116968aab37288ae2618634e44fc689ce0c433
|
7
|
+
data.tar.gz: 5d6ddf4e31fe4ae1d18973bf6719378037e9899d51627fdfc607813d8fff7de362d30aff0b4cb97343e13078414fde6a4a52e806e21f96fd572a0dfef740552e
|
@@ -82,9 +82,11 @@ class DataModeler::Dataset
|
|
82
82
|
include DataModeler::IteratingBasedOnNext # `#each` and `#to_a` based on `#next`
|
83
83
|
|
84
84
|
# Overloaded comparison for easier testing
|
85
|
+
# @param other [Dataset] what needs comparing to
|
86
|
+
# @return [void]
|
85
87
|
def == other
|
86
|
-
self.class == other.class &&
|
87
|
-
data.object_id == other.data.object_id &&
|
88
|
+
self.class == other.class && # terminate check here if wrong class
|
89
|
+
data.object_id == other.data.object_id && # both `data` point to same object
|
88
90
|
(instance_variables - [:@data]).all? do |var|
|
89
91
|
self.instance_variable_get(var) == other.instance_variable_get(var)
|
90
92
|
end
|
@@ -94,6 +96,8 @@ class DataModeler::Dataset
|
|
94
96
|
|
95
97
|
include DataModeler::ConvertingTimeAndIndices # `#time` and `#idx`
|
96
98
|
|
99
|
+
# Initializes input indices vector
|
100
|
+
# @return [Array<input_idx>]
|
97
101
|
def init_inputs
|
98
102
|
if target_idx < end_idx
|
99
103
|
# build list of incremental time buffers
|
@@ -98,6 +98,7 @@ class DataModeler::DatasetGen
|
|
98
98
|
|
99
99
|
# Check if there is enough data to build `min_nruns` train + test sets
|
100
100
|
# @raise [NotEnoughDataError] if `not enough minerals` (cit.)
|
101
|
+
# @return [void]
|
101
102
|
# @note remember the schema: need to check for `|win|train1|t1|t2|...|tn|`
|
102
103
|
def validate_enough_data_for min_nruns
|
103
104
|
min_data_size = min_eligible_trg + train_size + min_nruns * test_size
|
@@ -5,6 +5,10 @@ class DataModeler::Model::FANN
|
|
5
5
|
|
6
6
|
attr_reader :opts, :fann, :algo, :actfn
|
7
7
|
|
8
|
+
# @param netstruct [Array<ninputs, Array<hidden_layers>, noutputs>] network
|
9
|
+
# structure
|
10
|
+
# @param algo [:incremental, :batch, :rprop, :quickprop] training algorithm
|
11
|
+
# @param actfn [:sigmoid, ...] activation function
|
8
12
|
def initialize netstruct, algo: nil, actfn: nil
|
9
13
|
ninputs, hidden_layers, noutputs = netstruct
|
10
14
|
@opts = {
|
@@ -14,23 +18,25 @@ class DataModeler::Model::FANN
|
|
14
18
|
}
|
15
19
|
@algo = algo
|
16
20
|
@actfn = actfn
|
21
|
+
reset
|
17
22
|
end
|
18
23
|
|
24
|
+
# Resets / initializes the model
|
25
|
+
# @return [void]
|
19
26
|
def reset
|
20
27
|
@fann = RubyFann::Standard.new opts
|
21
|
-
|
22
|
-
if algo
|
23
|
-
fann.set_training_algorithm(algo)
|
24
|
-
end
|
25
|
-
|
28
|
+
fann.set_training_algorithm(algo) if algo
|
26
29
|
if actfn
|
27
30
|
fann.set_activation_function_hidden(actfn)
|
28
31
|
fann.set_activation_function_output(actfn)
|
29
32
|
end
|
30
|
-
|
31
|
-
return self # allows chaining for `model.reset.train`
|
33
|
+
nil
|
32
34
|
end
|
33
35
|
|
36
|
+
# Trains the model for ngens on the trainset
|
37
|
+
# @param ngens [Integer] number of training generations
|
38
|
+
# @param trainset [Hash-like<input: Array, target: Array>] training set
|
39
|
+
# @return [void]
|
34
40
|
def train ngens, trainset
|
35
41
|
tset = RubyFann::TrainData.new(
|
36
42
|
inputs: trainset[:input], desired_outputs: trainset[:target])
|
@@ -40,13 +46,19 @@ class DataModeler::Model::FANN
|
|
40
46
|
fann.train_on_data(tset, ngens, 1000, 1e-10)
|
41
47
|
end
|
42
48
|
|
49
|
+
# Tests the model on inputs.
|
50
|
+
# @param inputs [Array<Array<inputs>>] sequence of inputs for the model
|
51
|
+
# @return [Array<Array<outputs>>] outputs corresponding to each input
|
43
52
|
def test inputs
|
44
53
|
inputs.collect { |i| fann.run i }
|
45
54
|
end
|
46
55
|
|
56
|
+
# Save the model
|
57
|
+
# @param filename [String/path] where to save the model
|
58
|
+
# @return [void]
|
47
59
|
def save filename
|
48
60
|
# can do filename check here...?
|
49
|
-
# I'd
|
61
|
+
# TODO: I'd like to have a kind of `to_s`, and do all the saving in the modeler...
|
50
62
|
fann.save filename
|
51
63
|
end
|
52
64
|
end
|
data/lib/data_modeler/version.rb
CHANGED