Class: MLP::Network

Inherits:
Object
  • Object
show all
Defined in:
lib/mlp/network.rb

Constant Summary collapse

UPDATE_WEIGHT_VALUE =
0.25

Instance Method Summary collapse

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(options = {})
  @input_size = options[:inputs]
  @hidden_layers = options[:hidden_layers]
  @number_of_output_nodes = options[: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

#inspectObject



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