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.



376
377
378
379
# File 'lib/neuronet.rb', line 376

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

Instance Method Details

#set_center(inputs) ⇒ Object



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

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

#set_spread(inputs) ⇒ Object



385
386
387
388
389
# File 'lib/neuronet.rb', line 385

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