Class: MLP::Network
- Inherits:
-
Object
- Object
- MLP::Network
- Defined in:
- lib/mlp/network.rb
Constant Summary collapse
- UPDATE_WEIGHT_VALUE =
0.25
Instance Method Summary collapse
- #feed_forward(input) ⇒ Object
-
#initialize(options = {}) ⇒ Network
constructor
A new instance of Network.
- #inspect ⇒ Object
- #train(input, targets) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Network
Returns a new instance of Network.
8 9 10 11 12 13 |
# File 'lib/mlp/network.rb', line 8 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
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mlp/network.rb', line 15 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(&:last_output) neuron.fire(input) end end end @network.last.map(&:last_output) end |
#inspect ⇒ Object
37 38 39 |
# File 'lib/mlp/network.rb', line 37 def inspect @network end |
#train(input, targets) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/mlp/network.rb', line 29 def train(input, targets) # To go back we must go forward feed_forward(input) compute_deltas(targets) update_weights(input) calculate_error(targets) end |