Class: DataModeler::Model::FANN
- Inherits:
-
Object
- Object
- DataModeler::Model::FANN
- Defined in:
- lib/data_modeler/model/fann.rb
Overview
Model class based on Fast Artificial Neural Networks (FANN)
Instance Attribute Summary collapse
-
#actfn ⇒ Object
readonly
Returns the value of attribute actfn.
-
#algo ⇒ Object
readonly
Returns the value of attribute algo.
-
#fann ⇒ Object
readonly
Returns the value of attribute fann.
-
#fann_opts ⇒ Object
readonly
Returns the value of attribute fann_opts.
-
#ngens ⇒ Object
readonly
Returns the value of attribute ngens.
Instance Method Summary collapse
-
#initialize(ngens:, hidden_layers:, ninputs:, noutputs:, algo: nil, actfn: nil) ⇒ FANN
constructor
A new instance of FANN.
-
#reset ⇒ void
Resets / initializes the model.
-
#save(filename) ⇒ void
Save the model.
-
#test(inputs) ⇒ Array<Array<outputs>>
Tests the model on inputs.
-
#train(trainset, ngens = @ngens, report_interval: 1000, desired_error: 1e-10) ⇒ void
Trains the model for ngens on the trainset.
Constructor Details
#initialize(ngens:, hidden_layers:, ninputs:, noutputs:, algo: nil, actfn: nil) ⇒ FANN
Returns a new instance of FANN.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/data_modeler/model/fann.rb', line 15 def initialize ngens:, hidden_layers:, ninputs:, noutputs:, algo: nil, actfn: nil @fann_opts = { num_inputs: ninputs, hidden_neurons: hidden_layers, num_outputs: noutputs } @ngens = ngens @algo = algo @actfn = actfn reset end |
Instance Attribute Details
#actfn ⇒ Object (readonly)
Returns the value of attribute actfn.
6 7 8 |
# File 'lib/data_modeler/model/fann.rb', line 6 def actfn @actfn end |
#algo ⇒ Object (readonly)
Returns the value of attribute algo.
6 7 8 |
# File 'lib/data_modeler/model/fann.rb', line 6 def algo @algo end |
#fann ⇒ Object (readonly)
Returns the value of attribute fann.
6 7 8 |
# File 'lib/data_modeler/model/fann.rb', line 6 def fann @fann end |
#fann_opts ⇒ Object (readonly)
Returns the value of attribute fann_opts.
6 7 8 |
# File 'lib/data_modeler/model/fann.rb', line 6 def fann_opts @fann_opts end |
#ngens ⇒ Object (readonly)
Returns the value of attribute ngens.
6 7 8 |
# File 'lib/data_modeler/model/fann.rb', line 6 def ngens @ngens end |
Instance Method Details
#reset ⇒ void
This method returns an undefined value.
Resets / initializes the model
29 30 31 32 33 34 35 36 37 |
# File 'lib/data_modeler/model/fann.rb', line 29 def reset @fann = RubyFann::Standard.new fann_opts fann.set_training_algorithm(algo) if algo if actfn fann.set_activation_function_hidden(actfn) fann.set_activation_function_output(actfn) end nil end |
#save(filename) ⇒ void
This method returns an undefined value.
Save the model
63 64 65 66 67 |
# File 'lib/data_modeler/model/fann.rb', line 63 def save filename # can do filename check here...? # TODO: I'd like to have a kind of `to_s`, and do all the saving in the modeler... fann.save filename.to_s end |
#test(inputs) ⇒ Array<Array<outputs>>
Tests the model on inputs.
56 57 58 |
# File 'lib/data_modeler/model/fann.rb', line 56 def test inputs inputs.collect { |i| fann.run i } end |
#train(trainset, ngens = @ngens, report_interval: 1000, desired_error: 1e-10) ⇒ void
This method returns an undefined value.
Trains the model for ngens on the trainset
43 44 45 46 47 48 49 50 51 |
# File 'lib/data_modeler/model/fann.rb', line 43 def train trainset, ngens=@ngens, report_interval: 1000, desired_error: 1e-10 # TODO: optimize maybe? inputs, targets = trainset.values tset = RubyFann::TrainData.new inputs: inputs, desired_outputs: targets # fann.init_weights tset # test this weights initialization # params: train_data, max_epochs, report_interval, desired_error fann.train_on_data(tset, ngens, report_interval, desired_error) end |