In Files

Parent

Files

Bullshit::NormalDistribution

This class is used to compute the Normal Distribution.

Attributes

mu[R]

(Not documented)

sigma[R]

(Not documented)

Public Class Methods

new(mu = 0.0, sigma = 1.0) click to toggle source

Creates a NormalDistribution instance for the values mu and sigma.

# File lib/bullshit.rb, line 869
    def initialize(mu = 0.0, sigma = 1.0)
      @mu, @sigma = mu.to_f, sigma.to_f
    end

Public Instance Methods

inverse_probability(p) click to toggle source

Returns the inverse cumulative probability value of the NormalDistribution for the probability p.

# File lib/bullshit.rb, line 885
    def inverse_probability(p)
      case
      when p <= 0
        -1 / 0.0
      when p >= 1
        1 / 0.0
      when p == 0.5 # This is a bit sloppy, maybe improve this later.
        @mu
      else
        begin
          NewtonBisection.new { |x| probability(x) - p }.solve(nil, 1_000_000)
        rescue
          0 / 0.0
        end
      end
    end
probability(x) click to toggle source

Returns the cumulative probability (p-value) of the NormalDistribution for the value x.

# File lib/bullshit.rb, line 879
    def probability(x)
      0.5 * (1 + erf((x - @mu) / (@sigma * ROOT2)))
    end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.