class Normcore::Normal

The normal a.k.a. Gaussian distribution

en.wikipedia.org/wiki/Box–μller_transform

Usage:

normal = Normal.new(0, 1)

normal.rng # return one sample

normal.sample(10) # return 10 samples

Attributes

μ[R]
σ[R]

Public Class Methods

new(μ, σ) click to toggle source
# File lib/normal.rb, line 18
def initialize μ, σ
   = μ
   = σ
end

Public Instance Methods

rng() click to toggle source

yield samples from gaussian distribution using the Box-μller transform

# File lib/normal.rb, line 26
def rng
  box_muller
end

Private Instance Methods

box_muller() click to toggle source

Use the Box-μller transform to generate pairs of independent, standard, normally distributed random numbers.

# File lib/normal.rb, line 36
def box_muller
  θ = 2 * Math::PI * rand
  ρ = Math.sqrt(-2 * Math.log(1 - rand))
  scale = σ * ρ
  μ + scale * Math.cos(θ)
end