Class: Neuronet::Deep
- Inherits:
-
Object
- Object
- Neuronet::Deep
- Includes:
- Arrayable, Exportable, NetworkStats, Trainable
- Defined in:
- lib/neuronet/deep.rb
Overview
Feed Forward
Instance Attribute Summary collapse
-
#hidden_layers ⇒ Object
readonly
rubocop: enable Metrics.
-
#input_layer ⇒ Object
readonly
rubocop: enable Metrics.
-
#output_layer ⇒ Object
readonly
rubocop: enable Metrics.
Instance Method Summary collapse
- #*(other) ⇒ Object
-
#initialize(*sizes, input_neuron: InputNeuron, middle_neuron: MiddleNeuron, output_neuron: OutputNeuron) ⇒ Deep
constructor
rubocop: disable Metrics.
- #set(values) ⇒ Object
- #to_a ⇒ Object
- #update ⇒ Object
- #values ⇒ Object
Methods included from Arrayable
#[], #each, #each_with_index, #map, #reverse, #size
Methods included from Trainable
Methods included from Exportable
#export, #export_to_file, #import, #import_from_file
Methods included from NetworkStats
#expected_nju, #expected_nju!, #njus
Constructor Details
#initialize(*sizes, input_neuron: InputNeuron, middle_neuron: MiddleNeuron, output_neuron: OutputNeuron) ⇒ Deep
rubocop: disable Metrics
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/neuronet/deep.rb', line 12 def initialize(*sizes, input_neuron: InputNeuron, middle_neuron: MiddleNeuron, output_neuron: OutputNeuron) length = sizes.length raise 'Need at least 3 layers' if length < 3 @input_layer = InputLayer.new(sizes.shift, input_neuron:) @output_layer = OutputLayer.new(sizes.pop, output_neuron:) @hidden_layers = sizes.map { MiddleLayer.new(it, middle_neuron:) } previous = @input_layer @hidden_layers.each do |layer| layer.connect(previous) previous = layer end @output_layer.connect(previous) end |
Instance Attribute Details
#hidden_layers ⇒ Object (readonly)
rubocop: enable Metrics
30 31 32 |
# File 'lib/neuronet/deep.rb', line 30 def hidden_layers @hidden_layers end |
#input_layer ⇒ Object (readonly)
rubocop: enable Metrics
30 31 32 |
# File 'lib/neuronet/deep.rb', line 30 def input_layer @input_layer end |
#output_layer ⇒ Object (readonly)
rubocop: enable Metrics
30 31 32 |
# File 'lib/neuronet/deep.rb', line 30 def output_layer @output_layer end |
Instance Method Details
#*(other) ⇒ Object
44 45 46 47 48 |
# File 'lib/neuronet/deep.rb', line 44 def *(other) set(other) update values end |
#set(values) ⇒ Object
32 33 34 |
# File 'lib/neuronet/deep.rb', line 32 def set(values) @input_layer.set(values) end |
#to_a ⇒ Object
50 |
# File 'lib/neuronet/deep.rb', line 50 def to_a = [@input_layer, *@hidden_layers, @output_layer] |
#update ⇒ Object
36 37 38 |
# File 'lib/neuronet/deep.rb', line 36 def update @hidden_layers.each(&:update) end |
#values ⇒ Object
40 41 42 |
# File 'lib/neuronet/deep.rb', line 40 def values @output_layer.values end |