Class: Neuronet::Gaussian

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

Overview

“Normal Distribution” Gaussian sub-classes 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, #spread

Instance Method Summary collapse

Methods inherited from Scale

#initialize, #mapped, #reset, #unmapped

Constructor Details

This class inherits a constructor from Neuronet::Scale

Instance Method Details

#set(inputs) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/neuronet/gaussian.rb', line 10

def set(inputs)
  @center ||= inputs.sum.to_f / inputs.length
  unless @spread
    sum2 = inputs.map { @center - _1 }.sum { _1 * _1 }.to_f
    @spread = Math.sqrt(sum2 / (inputs.length - 1.0))
  end
  self
end