Class: BackProp::Layer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_count, output_count, activation: :relu) ⇒ Layer

Returns a new instance of Layer.



49
50
51
52
53
# File 'lib/perceptron.rb', line 49

def initialize(input_count, output_count, activation: :relu)
  @neurons = Array.new(output_count) {
    Neuron.new(input_count, activation: activation)
  }
end

Instance Attribute Details

#neuronsObject (readonly)

Returns the value of attribute neurons.



47
48
49
# File 'lib/perceptron.rb', line 47

def neurons
  @neurons
end

Instance Method Details

#apply(x = 0) ⇒ Object



55
56
57
# File 'lib/perceptron.rb', line 55

def apply(x = 0)
  @neurons.map { |n| n.apply(x) }
end

#descend(step_size) ⇒ Object



59
60
61
62
# File 'lib/perceptron.rb', line 59

def descend(step_size)
  @neurons.each { |n| n.descend(step_size) }
  self
end

#inspectObject



68
69
70
# File 'lib/perceptron.rb', line 68

def inspect
  @neurons.map(&:inspect).join("\n")
end

#to_sObject



64
65
66
# File 'lib/perceptron.rb', line 64

def to_s
  @neurons.join("\n")
end