Class: ProbabilityDistributions::GaussianDistribution

Inherits:
ProbabilityDistribution show all
Defined in:
lib/probability_distributions/gaussian_distribution.rb

Instance Method Summary collapse

Constructor Details

#initialize(average, variability, uniform_distribution = nil) ⇒ GaussianDistribution

Returns a new instance of GaussianDistribution.



10
11
12
13
# File 'lib/probability_distributions/gaussian_distribution.rb', line 10

def initialize ( average, variability, uniform_distribution=nil )
  raise unless uniform_distribution.is_a? UniformDistribution
  @uniform_distribution = uniform_distribution
end

Instance Method Details

#box_muller_conversionObject



15
16
17
18
19
# File 'lib/probability_distributions/gaussian_distribution.rb', line 15

def box_muller_conversion
  yA, yB = sqrt(-2 * log(@x1)), 2 * PI * @x2
  @y1 = yA * cos(yB)
  @y2 = yA * sin(yB)
end

#chooseObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/probability_distributions/gaussian_distribution.rb', line 21

def choose
  if @y2.nil?
    @x1, @x2 = @uniform_distribution.choose, @uniform_distribution.choose
    box_muller_conversion
    return @y1
  end
  res = @y2
  @y2 = nil
  return res
end