Class: Fathom::Distributions::Uniform

Inherits:
Object
  • Object
show all
Extended by:
SharedMethods
Defined in:
lib/fathom/distributions/uniform.rb

Class Method Summary collapse

Class Method Details

.interval_values(opts = {}) ⇒ Object



27
28
29
30
31
# File 'lib/fathom/distributions/uniform.rb', line 27

def interval_values(opts={})
  confidence_interval = opts.fetch(:confidence_interval, 0.9)
  bound = (1 - confidence_interval) / 2.0
  [lower_bound(opts.merge(:confidence_interval => bound)), upper_bound(opts.merge(:confidence_interval => bound))]
end

.inverse_cdf(opts = {}) ⇒ Object Also known as: lower_bound



13
14
15
16
17
18
19
20
# File 'lib/fathom/distributions/uniform.rb', line 13

def inverse_cdf(opts={})
  mean = opts[:mean]
  lower = opts.fetch(:lower, true)
  lower = false if opts[:upper]
  confidence_interval = opts.fetch(:confidence_interval, 0.05)
  value = lower ? GSL::Cdf.ugaussian_Pinv(confidence_interval) : GSL::Cdf.ugaussian_Qinv(confidence_interval)
  value + mean
end

.randObject



9
10
11
# File 'lib/fathom/distributions/uniform.rb', line 9

def rand
  rng.ugaussian
end

.rngObject



5
6
7
# File 'lib/fathom/distributions/uniform.rb', line 5

def rng
  @rng ||= GSL::Rng.alloc(GSL::Rng::MT19937_1999, Kernel.rand(100_000))
end

.upper_bound(opts = {}) ⇒ Object



23
24
25
# File 'lib/fathom/distributions/uniform.rb', line 23

def upper_bound(opts={})
  inverse_cdf(opts.merge(:lower => false))
end