Class: GSLng::RNG::Gaussian

Inherits:
GSLng::RNG show all
Defined in:
lib/gslng/rng/gaussian.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GSLng::RNG

#initialize_copy, release

Constructor Details

#initialize(mu = 0, sigma = 1, sample_method = :boxmuller, generator_type = nil) ⇒ Gaussian

Creates a new Gaussian distribution

Parameters:

  • mu (Float) (defaults to: 0)

    mean

  • sigma (Float) (defaults to: 1)

    standard deviation

  • sample_method (Symbol) (defaults to: :boxmuller)

    The method to use to sample numbers. Can be either :boxmuller, :ziggurat or :ratio_method

  • generator_type (Symbol) (defaults to: nil)

    the algorithm to use (without the gsl_rng prefix). Default is :mt19937.

See Also:


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gslng/rng/gaussian.rb', line 14

def initialize(mu = 0, sigma = 1, sample_method = :boxmuller, generator_type = nil)
  super(generator_type)
  @mu,@sigma = mu,sigma

  case sample_method
  when :boxmuller; @function = :gsl_ran_gaussian
  when :ziggurat; @function = :gsl_ran_gaussian_ziggurat
  when :ratio_method; @function = :gsl_ran_ratio_method
  else raise "Unsupported method"
  end
end

Instance Attribute Details

#muObject (readonly)

Returns the value of attribute mu


6
7
8
# File 'lib/gslng/rng/gaussian.rb', line 6

def mu
  @mu
end

#ptrObject (readonly)


4
5
6
# File 'lib/gslng/rng/gaussian.rb', line 4

def ptr
  @ptr
end

#sigmaObject (readonly)

Returns the value of attribute sigma


6
7
8
# File 'lib/gslng/rng/gaussian.rb', line 6

def sigma
  @sigma
end

Instance Method Details

#sampleFloat Also known as: get

Obtain a sample from this distribution

Returns:

  • (Float)

28
29
30
# File 'lib/gslng/rng/gaussian.rb', line 28

def sample
  GSLng.backend.send(@function, self.ptr, @sigma) + @mu
end