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])



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

#layersObject (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

#inspectObject



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

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

#parametersObject



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

def parameters
  @layers.map { |l| l.parameters }.flatten
end

#to_sObject



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

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