Sha256: be3e19a150e959fe57661d41952c086891230ab2996d0dd2f8f92b03db326273

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'fathom'))
class Fathom::Distributions::DiscreteUniform
  extend Fathom::Distributions::SharedMethods
  class << self
    def rng
      @rng ||= GSL::Rng.alloc(GSL::Rng::MT19937_1999, Kernel.rand(100_000))
    end
    
    def rand
      (rng.ugaussian / size).floor + 1
    end
    
    def inverse_cdf(opts={})
      mean = opts[:mean]
      sd = opts[:sd]
      sd ||= opts[:std]
      sd ||= opts[:standard_deviation]
      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
    alias :lower_bound :inverse_cdf

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

    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
    
    # If only I had the background to explain what this is....
    # I want to know how many standard deviations are expressed by the confidence interval
    # I can then divide  the range by this number to get the standard deviation
    def standard_deviations_under(confidence_interval)
      GSL::Cdf.ugaussian_Qinv((1 - confidence_interval) / 2) * 2
    end
    
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fathom-0.3.0 lib/fathom/distributions/discrete_uniform.rb
fathom-0.2.3 lib/fathom/distributions/discrete_uniform.rb