Module: Neuronet::Yang

Defined in:
lib/neuronet.rb

Overview

Yang is a network wich has its @out layer initially mirroring @yang.

Class Method Summary collapse

Class Method Details

.bless(myself) ⇒ Object

Yang.bless sets the bias of each @yang to 0.5, and the weight of pairing (@out, @yang) connections to one. This makes @out initially mirror @yang. The pairing is done starting with (@out, @yang). That is, starting with (@out.last, @yang.last).



510
511
512
513
514
515
516
517
518
519
520
521
# File 'lib/neuronet.rb', line 510

def self.bless(myself)
  offset = myself.yang.length - (out_length = (out = myself.out).length)
  raise "Last hidden layer, yang, needs to have at least the same length as output" if offset < 0
  # Although the algorithm here is not as described,
  # the net effect to is pair @out.last with @yang.last, and so on down.
  0.upto(out_length-1) do |index|
    node = out[index]
    node.connections[offset+index].weight = 1.0
    node.bias = -0.5
  end
  return myself
end