Class: BackProp::MLP

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_count, output_counts, activation: :relu) ⇒ MLP

MLP.new(3, [4, 4, 1])



77
78
79
80
81
82
# File 'lib/perceptron.rb', line 77

def initialize(input_count, output_counts, activation: :relu)
  flat = [input_count, *output_counts]
  @layers = output_counts.map.with_index { |oc, i|
    Layer.new(flat[i], flat[i+1], activation: activation)
  }
end

Instance Attribute Details

#layersObject (readonly)

Returns the value of attribute layers.



74
75
76
# File 'lib/perceptron.rb', line 74

def layers
  @layers
end

Instance Method Details

#apply(x = 0) ⇒ Object



84
85
86
87
88
# File 'lib/perceptron.rb', line 84

def apply(x = 0)
  @layers.each { |layer| x = layer.apply(x) }
  # x.size == 1 ? x.first : x
  x
end

#descend(step_size) ⇒ Object



90
91
92
93
# File 'lib/perceptron.rb', line 90

def descend(step_size)
  @layers.each { |l| l.descend(step_size) }
  self
end

#inspectObject



99
100
101
# File 'lib/perceptron.rb', line 99

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

#to_sObject



95
96
97
# File 'lib/perceptron.rb', line 95

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