Class: Neuronet::Layer

Inherits:
Object
  • Object
show all
Includes:
Arrayable, LayerPresets
Defined in:
lib/neuronet/layer.rb

Overview

Layer is a collection of neurons with array-like behavior.

Constant Summary

Constants included from LayerPresets

Neuronet::LayerPresets::BZERO, Neuronet::LayerPresets::WONE

Instance Method Summary collapse

Methods included from Arrayable

#[], #each, #each_with_index, #map, #reverse, #size

Methods included from LayerPresets

#antithesis, #average, #mirror, #synthesis

Constructor Details

#initialize(length, full_neuron: Neuron) ⇒ Layer

Creates layer with ‘length` number of neurons.



12
13
14
15
# File 'lib/neuronet/layer.rb', line 12

def initialize(length, full_neuron: Neuron)
  @layer = Array.new(length) { full_neuron.new }
  @endex = length - 1
end

Instance Method Details

#connect(layer) ⇒ Object

Fully connects this layer to another.



27
28
29
30
31
# File 'lib/neuronet/layer.rb', line 27

def connect(layer)
  each do |neuron|
    layer.each { neuron.connect(it) }
  end
end

#set(values) ⇒ Object

Set each neuron’s activation from values array. Allows the layer to be used as an input layer.



19
20
21
# File 'lib/neuronet/layer.rb', line 19

def set(values)
  0.upto(@endex) { @layer[it].set values[it] }
end

#to_aObject



39
# File 'lib/neuronet/layer.rb', line 39

def to_a = @layer

#updateObject

For each neuron in the layer, updates the neuron’s activation.



24
# File 'lib/neuronet/layer.rb', line 24

def update = @layer.each(&:update)

#valuesObject

Raw pre-squashed values of all neurons in the layer. Allows the layer to be use as an output layer.



35
36
37
# File 'lib/neuronet/layer.rb', line 35

def values
  @layer.map(&:value)
end