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
-
#initialize(input_count, output_counts, activation: :relu) ⇒ MLP
constructor
MLP.new(3, [4, 4, 1]).
- #inspect ⇒ Object
- #parameters ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(input_count, output_counts, activation: :relu) ⇒ MLP
MLP.new(3, [4, 4, 1])
73 74 75 76 77 78 |
# File 'lib/perceptron.rb', line 73 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.
70 71 72 |
# File 'lib/perceptron.rb', line 70 def layers @layers end |
Instance Method Details
#apply(x = 0) ⇒ Object
80 81 82 83 84 |
# File 'lib/perceptron.rb', line 80 def apply(x = 0) @layers.each { |layer| x = layer.apply(x) } # x.size == 1 ? x.first : x x end |
#inspect ⇒ Object
94 95 96 |
# File 'lib/perceptron.rb', line 94 def inspect @layers.map(&:inspect).join("\n\n") end |
#parameters ⇒ Object
86 87 88 |
# File 'lib/perceptron.rb', line 86 def parameters @layers.map { |l| l.parameters }.flatten end |
#to_s ⇒ Object
90 91 92 |
# File 'lib/perceptron.rb', line 90 def to_s @layers.join("\n\n") end |