Sha256: e2422f39bae878a1ec92a849ec5bc0111396d3020c048b6c2cf56e4213eeede6

Contents?: true

Size: 534 Bytes

Versions: 1

Compression:

Stored size: 534 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
distribution-0.8.0 lib/distribution/exponential/ruby.rb