Class: Rubystats::NormalDistribution
- Inherits:
-
ProbabilityDistribution
- Object
- ProbabilityDistribution
- Rubystats::NormalDistribution
- Includes:
- SpecialMath
- Defined in:
- lib/rubystats/normal_distribution.rb
Constant Summary
Constants included from NumericalConstants
Rubystats::NumericalConstants::EPS, Rubystats::NumericalConstants::GAMMA, Rubystats::NumericalConstants::GAMMA_X_MAX_VALUE, Rubystats::NumericalConstants::GOLDEN_RATIO, Rubystats::NumericalConstants::LOG_GAMMA_X_MAX_VALUE, Rubystats::NumericalConstants::MAX_FLOAT, Rubystats::NumericalConstants::MAX_ITERATIONS, Rubystats::NumericalConstants::MAX_VALUE, Rubystats::NumericalConstants::PRECISION, Rubystats::NumericalConstants::SQRT2, Rubystats::NumericalConstants::SQRT2PI, Rubystats::NumericalConstants::TWO_PI, Rubystats::NumericalConstants::XMININ
Instance Attribute Summary
Attributes included from SpecialMath
#log_beta_cache_p, #log_beta_cache_q, #log_beta_cache_res, #log_gamma_cache_res, #log_gamma_cache_x
Instance Method Summary collapse
-
#get_mean ⇒ Object
Returns the mean of the distribution.
-
#get_standard_deviation ⇒ Object
Returns the standard deviation of the distribution.
-
#get_variance ⇒ Object
Returns the variance of the distribution.
-
#initialize(mu = 0.0, sigma = 1.0) ⇒ NormalDistribution
constructor
Constructs a normal distribution (defaults to zero mean and unity variance).
Methods included from SpecialMath
#beta, #beta_fraction, #complementary_error, #error, #gamma, #gamma_fraction, #gamma_series_expansion, #incomplete_beta, #incomplete_gamma, #log_beta, #log_gamma, #orig_gamma
Methods inherited from ProbabilityDistribution
#cdf, #check_range, #find_root, #get_factorial, #icdf, #mean, #pdf, #rng, #variance
Methods included from ExtraMath
Constructor Details
#initialize(mu = 0.0, sigma = 1.0) ⇒ NormalDistribution
Constructs a normal distribution (defaults to zero mean and unity variance).
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rubystats/normal_distribution.rb', line 13 def initialize(mu=0.0, sigma=1.0) @mean = mu.to_f if sigma <= 0.0 raise "error, invalid sigma #{sigma}, should be > 0" end @stdev = sigma.to_f @variance = sigma**2 @pdf_denominator = SQRT2PI * Math.sqrt(@variance) @cdf_denominator = SQRT2 * Math.sqrt(@variance) @use_last = nil end |
Instance Method Details
#get_mean ⇒ Object
Returns the mean of the distribution
26 27 28 |
# File 'lib/rubystats/normal_distribution.rb', line 26 def get_mean return @mean end |
#get_standard_deviation ⇒ Object
Returns the standard deviation of the distribution
31 32 33 |
# File 'lib/rubystats/normal_distribution.rb', line 31 def get_standard_deviation return @stdev end |
#get_variance ⇒ Object
Returns the variance of the distribution
36 37 38 |
# File 'lib/rubystats/normal_distribution.rb', line 36 def get_variance return @variance end |