Class: Micrograd::Neuron

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n) ⇒ Neuron

Returns a new instance of Neuron.



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

def initialize(n)
  @weights = Array.new(n) { random_value }
  @bias = random_value
end

Instance Attribute Details

#biasObject (readonly)

Returns the value of attribute bias.



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

def bias
  @bias
end

#weightsObject (readonly)

Returns the value of attribute weights.



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

def weights
  @weights
end

Instance Method Details

#call(xs) ⇒ Object



12
13
14
15
16
# File 'lib/micrograd/neuron.rb', line 12

def call(xs)
  weights.zip(xs)
    .sum(bias) { |w, x| w * x }
    .tanh
end

#parametersObject



18
# File 'lib/micrograd/neuron.rb', line 18

def parameters = [*weights, bias]