Class: ProbabilityDistributions::GaussianDistribution
- Inherits:
-
ProbabilityDistribution
- Object
- ProbabilityDistribution
- ProbabilityDistributions::GaussianDistribution
- Defined in:
- lib/probability_distributions/gaussian_distribution.rb
Instance Method Summary collapse
- #box_muller_conversion ⇒ Object
- #choose ⇒ Object
-
#initialize(average, variability, uniform_distribution = nil) ⇒ GaussianDistribution
constructor
A new instance of GaussianDistribution.
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_conversion ⇒ Object
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 |
#choose ⇒ Object
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 |