Module: Distribution::Uniform::GSL_

Defined in:
lib/distribution/uniform/gsl.rb

Class Method Summary collapse

Class Method Details

.cdf(x, lower = 0, upper = 1) ⇒ Object

:nodoc:



21
22
23
24
# File 'lib/distribution/uniform/gsl.rb', line 21

def cdf(x, lower = 0, upper = 1)
  # rb-gsl/blob/master/ext/gsl_native/cdf.c#L644
  GSL::Cdf.flat_P(x, lower, upper)
end

.pdf(x, lower = 0, upper = 1) ⇒ Object

:nodoc:



15
16
17
18
# File 'lib/distribution/uniform/gsl.rb', line 15

def pdf(x, lower = 0, upper = 1)
  # rb-gsl/blob/master/ext/gsl_native/randist.c#L1732
  GSL::Ran.flat_pdf(x, lower, upper)
end

.quantile(qn, lower, upper) ⇒ Object Also known as: p_value

:nodoc:



27
28
29
30
# File 'lib/distribution/uniform/gsl.rb', line 27

def quantile(qn, lower, upper)
  # rb-gsl/blob/master/ext/gsl_native/cdf.c#L646
  GSL::Cdf.flat_Pinv(qn, lower, upper)
end

.rng(lower = 0, upper = 1, seed = nil) ⇒ Object

Returns a lambda to call for uniformly distributed random numbers returns a double precision float in [0, 1]



7
8
9
10
11
12
# File 'lib/distribution/uniform/gsl.rb', line 7

def rng(lower = 0, upper = 1, seed = nil)
  seed = Random.new_seed.modulo 100000007 if seed.nil?
  rng = GSL::Rng.alloc(GSL::Rng::MT19937, seed)
  
  -> { lower + (upper - lower) * rng.uniform }
end