Class: Layer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number_of_inputs, number_of_outputs, activation_function) ⇒ Layer



57
58
59
60
# File 'lib/nn.rb', line 57

def initialize(number_of_inputs, number_of_outputs, activation_function)
    @neurons = Array.new(number_of_outputs) { Neuron.new(number_of_inputs, activation_function) }
    @activation_function = activation_function
end

Instance Attribute Details

#activation_functionObject (readonly)

Returns the value of attribute activation_function.



62
63
64
# File 'lib/nn.rb', line 62

def activation_function
  @activation_function
end

#neuronsObject (readonly)

Returns the value of attribute neurons.



62
63
64
# File 'lib/nn.rb', line 62

def neurons
  @neurons
end

Instance Method Details

#calc(inputs) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/nn.rb', line 74

def calc(inputs)
    outs = []
    self.neurons.each do |neuron|
        outs << neuron.calc(inputs)
    end
    outs
end

#parametersObject



64
65
66
67
68
# File 'lib/nn.rb', line 64

def parameters
    params = []
    self.neurons.each { |n| params += n.parameters }
    params
end

#reset_paramsObject



70
71
72
# File 'lib/nn.rb', line 70

def reset_params
    self.neurons.each { |n| n.reset_params }
end