Class: Neuron

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/models/neuron.rb

Instance Method Summary collapse

Constructor Details

#initialize(number_of_inputs, layer_index) ⇒ Neuron

Returns a new instance of Neuron.



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

def initialize(number_of_inputs, layer_index)
  create_weights(number_of_inputs)
  self.layer_index = layer_index
end

Instance Method Details

#fire(input) ⇒ Object



14
15
16
# File 'lib/models/neuron.rb', line 14

def fire(input)
  self.last_output = activation_function(input)
end

#inspectObject



27
28
29
# File 'lib/models/neuron.rb', line 27

def inspect
  weights
end

#update_weight(inputs, training_rate) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/models/neuron.rb', line 18

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

#weightsObject



31
32
33
# File 'lib/models/neuron.rb', line 31

def weights
  db_weights.split(',').map {|x| x.to_f}
end