File: gsl.rb

package info (click to toggle)
ruby-distribution 0.8.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 624 kB
  • sloc: ruby: 4,535; makefile: 10
file content (27 lines) | stat: -rw-r--r-- 562 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module Distribution
  module Normal
    module GSL_
      class << self
        def rng(mean = 0, sigma = 1, seed = nil)
          seed ||= rand(10e8)
          rng = GSL::Rng.alloc(GSL::Rng::MT19937, seed)
          -> { mean + rng.gaussian(sigma) }
        end

        def cdf(x) # :nodoc:
          GSL::Cdf.ugaussian_P(x)
        end

        def pdf(x) # :nodoc:
          GSL::Ran.gaussian_pdf(x)
        end

        def quantile(qn)
          GSL::Cdf.ugaussian_Pinv(qn)
        end

        alias_method :p_value, :quantile
      end
    end
  end
end