Module: Neuronet::LayerPresets
- Included in:
- Layer, MiddleLayer, OutputLayer
- Defined in:
- lib/neuronet/layer_presets.rb
Overview
LayerPresets initializes layer weights/biases for interpret-able functions.
Constant Summary collapse
Instance Method Summary collapse
-
#antithesis ⇒ Object
Doubles up the input both mirroring and anti-mirroring it.
-
#average(sign = 1.0) ⇒ Object
Set layer to average input.
-
#mirror(sign = 1.0) ⇒ Object
Set layer to roughly mirror it’s input.
-
#synthesis(sign = 1.0) ⇒ Object
Sums two corresponding input neurons above each neuron in the layer.
Instance Method Details
#antithesis ⇒ Object
Doubles up the input both mirroring and anti-mirroring it. The layer should be twice the size of the input.
20 21 22 23 24 25 26 27 |
# File 'lib/neuronet/layer_presets.rb', line 20 def antithesis sign = 1.0 each_with_index do |neuron, index| neuron.bias = sign * BZERO neuron.connections[index / 2].weight = sign * WONE sign = -sign end end |
#average(sign = 1.0) ⇒ Object
Set layer to average input.
43 44 45 46 47 48 49 50 51 |
# File 'lib/neuronet/layer_presets.rb', line 43 def average(sign = 1.0) bias = sign * BZERO each do |neuron| neuron.bias = bias connections = neuron.connections weight = sign * WONE / connections.size connections.each { it.weight = weight } end end |
#mirror(sign = 1.0) ⇒ Object
Set layer to roughly mirror it’s input. Input should be the same size as the layer.
11 12 13 14 15 16 |
# File 'lib/neuronet/layer_presets.rb', line 11 def mirror(sign = 1.0) each_with_index do |neuron, index| neuron.bias = sign * BZERO neuron.connections[index].weight = sign * WONE end end |
#synthesis(sign = 1.0) ⇒ Object
Sums two corresponding input neurons above each neuron in the layer. Input should be twice the size of the layer.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/neuronet/layer_presets.rb', line 31 def synthesis(sign = 1.0) semi = sign * WONE / 2.0 each_with_index do |neuron, index| neuron.bias = sign * BZERO j = index * 2 connections = neuron.connections connections[j].weight = semi connections[j + 1].weight = semi end end |