Sha256: a7f3d5dcde9141b7c7db285cf07549093118c60ab944a3c58e09dda44de93a1b

Contents?: true

Size: 593 Bytes

Versions: 2

Compression:

Stored size: 593 Bytes

Contents

# frozen_string_literal: true

#
# Internal class for Marsaglia and Tsang's method.
#
# The method cannot be applied for `alpha < 1` without do anything.
# (Where `alpha` is shape parameter of Gamma distribution.)
# So this class achieves it with sampling from other Gamma distribution
# with `alpha` plus 1 and modifying it.
#
class Distrb::Gamma::MarsagliaTsang::LowAlpha
  def initialize alpha
    @alpha = alpha
    @gamma = Distrb::Gamma.new @alpha + 1
    @uniform = Distrb::Uniform.new
  end

  def sample
    x = @gamma.sample
    u = @uniform.sample
    x * u**(1 / @alpha)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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