Class: NeuralNetwork::Network
- Inherits:
-
Object
- Object
- NeuralNetwork::Network
- Defined in:
- lib/neural_network/network.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#hidden_layers ⇒ Object
Returns the value of attribute hidden_layers.
-
#input_layer ⇒ Object
Returns the value of attribute input_layer.
-
#output_layer ⇒ Object
Returns the value of attribute output_layer.
Instance Method Summary collapse
- #activate(input_values) ⇒ Object
-
#initialize(layer_sizes) ⇒ Network
constructor
A new instance of Network.
-
#train(target_outputs) ⇒ Object
all layers in reverse, back propogate!!.
Constructor Details
#initialize(layer_sizes) ⇒ Network
Returns a new instance of Network.
5 6 7 8 9 10 11 12 |
# File 'lib/neural_network/network.rb', line 5 def initialize(layer_sizes) @input_layer = Layer.new(layer_sizes.shift) @output_layer = Layer.new(layer_sizes.pop) @hidden_layers = layer_sizes.map{|layer_size| Layer.new(layer_size)} @error = 0 connect_layers end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
3 4 5 |
# File 'lib/neural_network/network.rb', line 3 def error @error end |
#hidden_layers ⇒ Object
Returns the value of attribute hidden_layers.
3 4 5 |
# File 'lib/neural_network/network.rb', line 3 def hidden_layers @hidden_layers end |
#input_layer ⇒ Object
Returns the value of attribute input_layer.
3 4 5 |
# File 'lib/neural_network/network.rb', line 3 def input_layer @input_layer end |
#output_layer ⇒ Object
Returns the value of attribute output_layer.
3 4 5 |
# File 'lib/neural_network/network.rb', line 3 def output_layer @output_layer end |
Instance Method Details
#activate(input_values) ⇒ Object
14 15 16 17 18 |
# File 'lib/neural_network/network.rb', line 14 def activate(input_values) @input_layer.activate(input_values) @hidden_layers.each(&:activate) @output_layer.activate end |
#train(target_outputs) ⇒ Object
all layers in reverse, back propogate!!
21 22 23 24 25 26 27 28 29 |
# File 'lib/neural_network/network.rb', line 21 def train(target_outputs) @output_layer.train(target_outputs) # set the new network error after training @error = error_function(target_outputs) @hidden_layers.reverse.each(&:train) @input_layer.train end |