Class: Neuron

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number_of_inputs) ⇒ Neuron

Returns a new instance of Neuron.



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

def initialize(number_of_inputs)
  create_weights(number_of_inputs)
end

Instance Attribute Details

#deltaObject

Returns the value of attribute delta.



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

def delta
  @delta
end

#last_outputObject (readonly)

Returns the value of attribute last_output.



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

def last_output
  @last_output
end

#weightsObject (readonly)

Returns the value of attribute weights.



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

def weights
  @weights
end

Instance Method Details

#fire(input) ⇒ Object



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

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

#inspectObject



21
22
23
# File 'lib/neuron.rb', line 21

def inspect
  @weights
end

#update_weight(inputs, training_rate) ⇒ Object



14
15
16
17
18
19
# File 'lib/neuron.rb', line 14

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