Sha256: 9fdfdab606f76bd3e1c590d44cab3eabda5f610c48d3ebc32d0f41bc443938b4

Contents?: true

Size: 463 Bytes

Versions: 2

Compression:

Stored size: 463 Bytes

Contents

# frozen_string_literal: true

#
# Marsaglia and Tsang's method to sample from Gamma distribution
# See: https://dl.acm.org/citation.cfm?id=358414
#
class Distrb::Gamma::MarsagliaTsang
  require_relative './marsaglia_tsang/high_alpha'
  require_relative './marsaglia_tsang/low_alpha'

  def initialize shape, rate = 1
    @sampler = shape < 1 ? LowAlpha.new(shape) : HighAlpha.new(shape)
    @rate = rate
  end

  def sample
    @sampler.sample / @rate
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
distrb-0.1.1 lib/distrb/gamma/marsaglia_tsang.rb
distrb-0.1.0 lib/distrb/gamma/marsaglia_tsang.rb