Module: Distribution::Uniform::Ruby_
 Defined in:
 lib/distribution/uniform/ruby.rb
Class Method Summary collapse

.cdf(x, lower = 0, upper = 1) ⇒ Object
The uniform cumulative density function (CDF) == Arguments If you are referring the wiki page for this continuous distribution the arguments can be translated as follows * +x+  same as continuous random variable * +lower+  lower limit or a, must be a real number * +upper+  upper limit or b, must be a real number.

.pdf(x, lower = 0, upper = 1) ⇒ Object
Uniform probability density function on [a, b].

.quantile(qn, lower = 0, upper = 1) ⇒ Object
(also: p_value)
The uniform inverse CDF density function / Pvalue function == Arguments If you are referring the wiki page for this continuous distribution the arguments can be translated as follows * +qn+  same as integral value * +lower+  lower limit or a, must be a real number * +upper+  upper limit or b, must be a real number.

.rng(lower = 0, upper = 1, seed = nil) ⇒ Object
Returns a lambda that emits a uniformly distributed sequence of random numbers between the defined limits.
Class Method Details
.cdf(x, lower = 0, upper = 1) ⇒ Object
The uniform cumulative density function (CDF) == Arguments If you are referring the wiki page for this continuous distribution the arguments can be translated as follows
 +x+  same as continuous random variable
 +lower+  lower limit or a, must be a real number
 +upper+  upper limit or b, must be a real number
== Reference
The implementation has been adpoted from GSL1.9 gsl/cdf/flat.c
54 55 56 57 58 59 60 61 62 
# File 'lib/distribution/uniform/ruby.rb', line 54 def cdf(x, lower = 0, upper = 1) if x < lower 0 elsif x > upper 1 else (x  lower) / (upper  lower) end end 
.pdf(x, lower = 0, upper = 1) ⇒ Object
Uniform probability density function on [a, b]
== Arguments If you are referring the wiki page for this continuous distribution the arguments can be translated as follows
 +x+  same as continuous random variable
 +lower+  lower limit or a, must be a real number
 +upper+  upper limit or b, must be a real number
== Reference
The implementation has been adopted from GSL1.9 gsl/randist/flat.c
35 36 37 38 39 
# File 'lib/distribution/uniform/ruby.rb', line 35 def pdf(x, lower = 0, upper = 1) upper, lower = lower, upper if lower > upper return 1 / (upper  lower) if (lower..upper).member? x 0 end 
.quantile(qn, lower = 0, upper = 1) ⇒ Object Also known as: p_value
The uniform inverse CDF density function / Pvalue function == Arguments If you are referring the wiki page for this continuous distribution the arguments can be translated as follows
 +qn+  same as integral value
 +lower+  lower limit or a, must be a real number
 +upper+  upper limit or b, must be a real number
== Returns
 nil if the integral value is not in [0, 1]
 inverse cdf otherwise == Reference
 https://en.wikipedia.org/wiki/Uniform_distribution_(continuous)
The implementation has been adpoted from GSL1.9 gsl/cdf/flatinv.c
80 81 82 83 84 85 
# File 'lib/distribution/uniform/ruby.rb', line 80 def quantile(qn, lower = 0, upper = 1) fail RangeError, 'cdf value(qn) must be from [0, 1]. '\ "Cannot find quantile for qn=#{qn}" if qn > 1  qn < 0 qn * upper + (1  qn) * lower end 
.rng(lower = 0, upper = 1, seed = nil) ⇒ Object
Returns a lambda that emits a uniformly distributed sequence of random numbers between the defined limits
== Arguments
 +lower+  Lower limit of the distribution
 +upper+  Upper limit of the distribution
 +seed+  Seed to set the initial state, randomized if ommited
15 16 17 18 19 
# File 'lib/distribution/uniform/ruby.rb', line 15 def rng(lower = 0, upper = 1, seed = nil) seed = Random.new_seed if seed.nil? prng = Random.new(seed) > { prng.rand * (upper  lower) + lower } end 