Class: BackProp::MLP
- Inherits:
-
Object
- Object
- BackProp::MLP
- Defined in:
- lib/perceptron.rb
Instance Attribute Summary collapse
-
#layers ⇒ Object
readonly
Returns the value of attribute layers.
Instance Method Summary collapse
- #apply(x = 0) ⇒ Object
- #descend(step_size) ⇒ Object
-
#initialize(input_count, output_counts, activation: :relu) ⇒ MLP
constructor
MLP.new(3, [4, 4, 1]).
- #inspect ⇒ Object
- #to_s ⇒ Object
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
#layers ⇒ Object (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 |
#inspect ⇒ Object
99 100 101 |
# File 'lib/perceptron.rb', line 99 def inspect @layers.map(&:inspect).join("\n\n") end |
#to_s ⇒ Object
95 96 97 |
# File 'lib/perceptron.rb', line 95 def to_s @layers.join("\n\n") end |