Class: MLP::Neuron

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number_of_inputs) ⇒ Neuron

Returns a new instance of Neuron.



9
10
11
# File 'lib/mlp/neuron.rb', line 9

def initialize(number_of_inputs)
  create_weights(number_of_inputs)
end

Instance Attribute Details

#deltaObject

Returns the value of attribute delta.



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

def delta
  @delta
end

#last_outputObject (readonly)

Returns the value of attribute last_output.



6
7
8
# File 'lib/mlp/neuron.rb', line 6

def last_output
  @last_output
end

#weightsObject (readonly)

Returns the value of attribute weights.



6
7
8
# File 'lib/mlp/neuron.rb', line 6

def weights
  @weights
end

Instance Method Details

#fire(input) ⇒ Object



13
14
15
# File 'lib/mlp/neuron.rb', line 13

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

#inspectObject



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

def inspect
  @weights
end

#update_weight(inputs, training_rate) ⇒ Object



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

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