MHSampler

class ssapy.rvsampler.MHSampler(probfn, initializer, proposer, nChain)[source][source]

Bases: object

Generate MCMC samples using a Metropolis-Hastings sampler.

Parameters:
  • probfn (Callable) – Callable that accepts sampling parameters p and returns posterior probability.

  • initializer (Callable) – Callable that accepts number of desired initial samples and returns samples. Note, the initial samples should be (at least mostly) unique.

  • proposer (Callable) – Callable that accepts a “current” sample and returns a “proposed” sample to either accept or reject at each step.

  • nChain (int) – Number of independent chains to use.

probfn[source]
initializer[source]
proposer[source]
nChain[source]
chain[source]

MCMC sample chain.

Type:

array_like (nStep, nChain, 6)

lnprob[source]

Log posterior probability of sample chain.

Type:

array_like (nStep, nChain)

nAccept[source]

Total number of accepted proposals.

Type:

int

nStep[source]

Total number of proposal steps.

Type:

int

reset()[source][source]

Reset chains.

sample(nBurn, nStep)[source][source]

Generate samples, first discarding nBurn steps, and then keeping nStep steps.

Attributes Summary

acceptanceRatio

Ratio of accepted to proposed steps.

Methods Summary

reset()

Reset chain, including chain, lnprob, nAccept, and nStep attributes.

sample([nBurn, nStep])

Generate samples.

Attributes Documentation

acceptanceRatio[source]

Ratio of accepted to proposed steps.

Methods Documentation

reset()[source][source]

Reset chain, including chain, lnprob, nAccept, and nStep attributes.

sample(nBurn=1000, nStep=500)[source][source]

Generate samples.

Parameters:
  • nBurn (int) – Number of initial steps to take but discard.

  • nStep (int) – Number of subsequent steps to keep and return.

Returns:

  • chain (array (nStep, nChain, 6)) – Generated samples. Columns are [x, y, z, vx, vy, vz].

  • lnprob (array (nStep, nChain)) – The log posterior probabilities of the samples.

  • lnprior (array (nStep, nChain)) – The log prior probabilities of the samples.