Sha256: d0855fc1e56c7bf71342b2a989e1170954a637e66480c5576ff6aa53a4dc6d3b

Contents?: true

Size: 498 Bytes

Versions: 2

Compression:

Stored size: 498 Bytes

Contents

# frozen_string_literal: true

#
# Sampling from Beta distribution using two Gamma ditributions
# Porting from Numpy
# See: https://github.com/numpy/numpy/blob/69fb4f160518ac347efc63dc17ebdf81285c1958/numpy/random/mtrand/distributions.c#L219-L224
#
class Distrb::Beta::TGV
  def initialize alpha, beta
    @gamma_alpha = Distrb::Gamma.new alpha, 1
    @gamma_beta = Distrb::Gamma.new beta, 1
  end

  def sample
    r1 = @gamma_alpha.sample
    r2 = @gamma_beta.sample
    r1 / (r1 + r2)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
distrb-0.1.1 lib/distrb/beta/tgv.rb
distrb-0.1.0 lib/distrb/beta/tgv.rb