Class: Digiproc::Probability::TheoreticalGaussianDistribution
- Inherits:
-
Object
- Object
- Digiproc::Probability::TheoreticalGaussianDistribution
- Defined in:
- lib/probability/theoretical_gaussian_distribution.rb
Overview
Class to calculate probabilities based off of a gaussian distributed random variable.
Instance Attribute Summary collapse
-
#mean ⇒ Object
readonly
Returns the value of attribute mean.
-
#stddev ⇒ Object
readonly
Returns the value of attribute stddev.
-
#variance ⇒ Object
readonly
Returns the value of attribute variance.
Instance Method Summary collapse
-
#cdf(x) ⇒ Object
Return the cdf [Float] of an input x [Float] gd = Digiproc::Probability::TheoreticalGaussianDistribution.new(mean: 0, stddev: 1) gd.cdf(0.3) # => 0.6179114221889526.
-
#initialize(mean:, stddev:, generator_strategy: Digiproc::Strategies::GaussianGeneratorBoxMullerStrategy) ⇒ TheoreticalGaussianDistribution
constructor
A new instance of TheoreticalGaussianDistribution.
-
#p_between(lower, upper) ⇒ Object
Return the probability [Float] of the random variable being between an upper [Float] and lower [Float] value gd = Digiproc::Probability::TheoreticalGaussianDistribution.new(mean: 0, stddev: 1) gd.p_between(-1, 1) # => 0.6826894921370859.
-
#p_outside(lower, upper) ⇒ Object
Return the probability [Float] of the random variable being outside an upper [Float] and lower [Float] value gd = Digiproc::Probability::TheoreticalGaussianDistribution.new(mean: 0, stddev: 1) gd.p_outside(-1, 1) # => 0.31731050786291415.
-
#q(x) ⇒ Object
Return the q value [Float] of an input x [Float] gd = Digiproc::Probability::TheoreticalGaussianDistribution.new(mean: 0, stddev: 1) gd.q(0.3) # => 0.3820885778110474.
-
#rand ⇒ Object
Outputs a single random number from the gaussian distribution gd.rand # => 1.4173209026395848.
Constructor Details
#initialize(mean:, stddev:, generator_strategy: Digiproc::Strategies::GaussianGeneratorBoxMullerStrategy) ⇒ TheoreticalGaussianDistribution
Returns a new instance of TheoreticalGaussianDistribution.
7 8 9 10 11 |
# File 'lib/probability/theoretical_gaussian_distribution.rb', line 7 def initialize(mean: , stddev: , generator_strategy: Digiproc::Strategies::GaussianGeneratorBoxMullerStrategy) @mean, @stddev = mean, stddev @variance = stddev ** 2 @generator_strategy = generator_strategy.new(mean, stddev) end |
Instance Attribute Details
#mean ⇒ Object (readonly)
Returns the value of attribute mean.
5 6 7 |
# File 'lib/probability/theoretical_gaussian_distribution.rb', line 5 def mean @mean end |
#stddev ⇒ Object (readonly)
Returns the value of attribute stddev.
5 6 7 |
# File 'lib/probability/theoretical_gaussian_distribution.rb', line 5 def stddev @stddev end |
#variance ⇒ Object (readonly)
Returns the value of attribute variance.
5 6 7 |
# File 'lib/probability/theoretical_gaussian_distribution.rb', line 5 def variance @variance end |
Instance Method Details
#cdf(x) ⇒ Object
Return the cdf [Float] of an input x [Float] gd = Digiproc::Probability::TheoreticalGaussianDistribution.new(mean: 0, stddev: 1) gd.cdf(0.3) # => 0.6179114221889526
17 18 19 |
# File 'lib/probability/theoretical_gaussian_distribution.rb', line 17 def cdf(x) 1 - q(x) end |
#p_between(lower, upper) ⇒ Object
Return the probability [Float] of the random variable being between an upper [Float] and lower [Float] value gd = Digiproc::Probability::TheoreticalGaussianDistribution.new(mean: 0, stddev: 1) gd.p_between(-1, 1) # => 0.6826894921370859
34 35 36 |
# File 'lib/probability/theoretical_gaussian_distribution.rb', line 34 def p_between(lower, upper) cdf(upper) - cdf(lower) end |
#p_outside(lower, upper) ⇒ Object
Return the probability [Float] of the random variable being outside an upper [Float] and lower [Float] value gd = Digiproc::Probability::TheoreticalGaussianDistribution.new(mean: 0, stddev: 1) gd.p_outside(-1, 1) # => 0.31731050786291415
42 43 44 |
# File 'lib/probability/theoretical_gaussian_distribution.rb', line 42 def p_outside(lower, upper) cdf(lower) + q(upper) end |
#q(x) ⇒ Object
Return the q value [Float] of an input x [Float] gd = Digiproc::Probability::TheoreticalGaussianDistribution.new(mean: 0, stddev: 1) gd.q(0.3) # => 0.3820885778110474
25 26 27 28 |
# File 'lib/probability/theoretical_gaussian_distribution.rb', line 25 def q(x) xform_x = xform_x_to_standard(x) 0.5 * Math.erfc(xform_x / (2 ** 0.5)) end |
#rand ⇒ Object
Outputs a single random number from the gaussian distribution gd.rand # => 1.4173209026395848
49 50 51 |
# File 'lib/probability/theoretical_gaussian_distribution.rb', line 49 def rand @generator_strategy.rand end |