Class: MoreMath::NormalDistribution
- Includes:
- Constants::FunctionsConstants, Functions
- Defined in:
- lib/more_math/distributions.rb
Overview
This class is used to compute the Normal Distribution.
Constant Summary
Constants included from Constants::FunctionsConstants
Constants::FunctionsConstants::ERF_A, Constants::FunctionsConstants::HALF_LOG_2_PI, Constants::FunctionsConstants::LANCZOS_COEFFICIENTS, Constants::FunctionsConstants::ROOT2
Instance Attribute Summary collapse
-
#mu ⇒ Object
readonly
Returns the value of attribute mu.
-
#sigma ⇒ Object
readonly
Returns the value of attribute sigma.
Instance Method Summary collapse
-
#initialize(mu = 0.0, sigma = 1.0) ⇒ NormalDistribution
constructor
Creates a NormalDistribution instance for the values
mu
andsigma
. -
#inverse_probability(p) ⇒ Object
Returns the inverse cumulative probability value of the NormalDistribution for the probability
p
. -
#probability(x) ⇒ Object
Returns the cumulative probability (p-value) of the NormalDistribution for the value
x
.
Methods included from Functions
beta, beta_regularized, cantor_pairing, cantor_pairing_inv, #erf, #erfc, gamma, gammaP_regularized, gammaQ_regularized, log_beta, log_ceil, log_floor, #log_gamma, logb, numberify_string, stringify_number
Constructor Details
#initialize(mu = 0.0, sigma = 1.0) ⇒ NormalDistribution
Creates a NormalDistribution instance for the values mu
and sigma
.
11 12 13 |
# File 'lib/more_math/distributions.rb', line 11 def initialize(mu = 0.0, sigma = 1.0) @mu, @sigma = mu.to_f, sigma.to_f end |
Instance Attribute Details
#mu ⇒ Object (readonly)
Returns the value of attribute mu.
15 16 17 |
# File 'lib/more_math/distributions.rb', line 15 def mu @mu end |
#sigma ⇒ Object (readonly)
Returns the value of attribute sigma.
17 18 19 |
# File 'lib/more_math/distributions.rb', line 17 def sigma @sigma end |
Instance Method Details
#inverse_probability(p) ⇒ Object
Returns the inverse cumulative probability value of the NormalDistribution for the probability p
.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/more_math/distributions.rb', line 27 def inverse_probability(p) case when p <= 0 -1 / 0.0 when p >= 1 1 / 0.0 when (p - 0.5).abs <= Float::EPSILON @mu else begin NewtonBisection.new { |x| probability(x) - p }.solve(nil, 1_000_000) rescue 0 / 0.0 end end end |