File: ruby.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 (28 lines) | stat: -rw-r--r-- 534 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
28
module Distribution
  module Exponential
    module Ruby_
      class << self
        def rng(l, opts = {})
          rng = opts[:random] || Random
          -> { p_value(rng.rand, l) }
        end

        def pdf(x, l)
          return 0 if x < 0
          l * Math.exp(-l * x)
        end

        def cdf(x, l)
          return 0 if x < 0
          1 - Math.exp(-l * x)
        end

        def quantile(pr, l)
          (-Math.log(1 - pr)).quo(l)
        end

        alias_method :p_value, :quantile
      end
    end
  end
end