Class: Neuronet::Gaussian

Inherits:
Scale
  • Object
show all
Defined in:
lib/neuronet.rb

Overview

“Normal Distribution” Gaussian subclasses Scale and is used exactly the same way. The only changes are that it calculates the arithmetic mean (average) for center and the standard deviation for spread.

Direct Known Subclasses

LogNormal

Instance Attribute Summary

Attributes inherited from Scale

#center, #init, #spread

Instance Method Summary collapse

Methods inherited from Scale

#mapped, #set, #set_init, #unmapped

Constructor Details

#initialize(factor = 1.0, center = nil, spread = nil) ⇒ Gaussian

Returns a new instance of Gaussian.



379
380
381
382
# File 'lib/neuronet.rb', line 379

def initialize(factor=1.0,center=nil,spread=nil)
  super(factor, center, spread)
  self.init = false
end

Instance Method Details

#set_center(inputs) ⇒ Object



384
385
386
# File 'lib/neuronet.rb', line 384

def set_center(inputs)
  self.center = inputs.inject(0.0,:+) / inputs.length
end

#set_spread(inputs) ⇒ Object



388
389
390
391
392
# File 'lib/neuronet.rb', line 388

def set_spread(inputs)
  self.spread = Math.sqrt(inputs.map{|value|
    self.center - value}.inject(0.0){|sum,value|
      value*value + sum} / (inputs.length - 1.0))
end