Class: Neuron

Inherits:
Object
  • Object
show all
Defined in:
lib/db_mlp/neuron.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number_of_inputs, layer_index) ⇒ Neuron

Returns a new instance of Neuron.


7
8
9
10
# File 'lib/db_mlp/neuron.rb', line 7

def initialize(number_of_inputs, layer_index)
  create_weights(number_of_inputs)
  @layer_index = layer_index
end

Instance Attribute Details

#deltaObject

Returns the value of attribute delta.


3
4
5
# File 'lib/db_mlp/neuron.rb', line 3

def delta
  @delta
end

#last_outputObject (readonly)

Returns the value of attribute last_output.


5
6
7
# File 'lib/db_mlp/neuron.rb', line 5

def last_output
  @last_output
end

#layer_indexObject (readonly)

Returns the value of attribute layer_index.


5
6
7
# File 'lib/db_mlp/neuron.rb', line 5

def layer_index
  @layer_index
end

Instance Method Details

#fire(input) ⇒ Object


12
13
14
# File 'lib/db_mlp/neuron.rb', line 12

def fire(input)
  @last_output = activation_function(input)
end

#inspectObject


24
25
26
# File 'lib/db_mlp/neuron.rb', line 24

def inspect
  weights
end

#update_weight(inputs, training_rate) ⇒ Object


16
17
18
19
20
21
22
# File 'lib/db_mlp/neuron.rb', line 16

def update_weight(inputs, training_rate)
  inputs << -1  # Add the bias node
      
  weights.each_index do |i|
    weights[i] +=  training_rate * delta * inputs[i]
  end
end

#weightsObject


28
29
30
# File 'lib/db_mlp/neuron.rb', line 28

def weights
  @weights ||= []
end