class MoreMath::NormalDistribution

This class is used to compute the Normal Distribution.

def initialize(mu = 0.0, sigma = 1.0)

Creates a NormalDistribution instance for the values +mu+ and +sigma+.
def initialize(mu = 0.0, sigma = 1.0)
  @mu, @sigma = mu.to_f, sigma.to_f
end

def inverse_probability(p)

NormalDistribution for the probability +p+.
Returns the inverse cumulative probability value of the
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

def probability(x)

for the value +x+.
Returns the cumulative probability (p-value) of the NormalDistribution
def probability(x)
  0.5 * (1 + erf((x - @mu) / (@sigma * ROOT2)))
end