Class: MLP
- Inherits:
-
Object
- Object
- MLP
- Defined in:
- lib/mlp.rb
Instance Method Summary collapse
- #feed_forward(input) ⇒ Object
-
#initialize(options = {}) ⇒ MLP
constructor
A new instance of MLP.
- #inspect ⇒ Object
- #train(input, targets) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ MLP
5 6 7 8 9 10 |
# File 'lib/mlp.rb', line 5 def initialize(={}) @input_size = [:inputs] @hidden_layers = [:hidden_layers] @number_of_output_nodes = [:output_nodes] setup_network end |
Instance Method Details
#feed_forward(input) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mlp.rb', line 12 def feed_forward(input) @network.each_with_index do |layer, layer_index| layer.each do |neuron| if layer_index == 0 neuron.fire(input) else input = @network[layer_index-1].map {|x| x.last_output} neuron.fire(input) end end end @network.last.map {|x| x.last_output} end |
#inspect ⇒ Object
34 35 36 |
# File 'lib/mlp.rb', line 34 def inspect @network end |
#train(input, targets) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/mlp.rb', line 26 def train(input, targets) # To go back we must go forward feed_forward(input) compute_deltas(targets) update_weights(input) calculate_error(targets) end |