hyperiax.mcmc package

Submodules

hyperiax.mcmc.fixedparameter module

class hyperiax.mcmc.fixedparameter.FixedParameter(value)

Bases: Parameter

A parameter that is constant regardless of updates. The parameter always have the value passed in the constructor

log_prior()

Logarithm of the prior probability of the parameter

Returns:

  1. as the parameter is fixed

propose(key)

Propose a new value for the parameter

Parameters:

key – A key to sample with

Returns:

Copy of the parameter

update(value, accepted)

Update the parameter. Does nothing as the parameter is fixed, i.e. the new value is discarded

Parameters:
  • value – The new value to update the parameter with

  • accepted – Whether the new value was accepted

hyperiax.mcmc.metropolis_hastings module

hyperiax.mcmc.metropolis_hastings.metropolis_hastings(log_target, proposal, data, init, num_samples, burn_in=0, thin=1, rng_key=None, savef=<function <lambda>>)

MCMC using Metropolis-Hastings algorithm

Parameters:
  • log_target – Function returning the logarithm of the target distribution

  • proposal – Function returning a sample from the proposal distribution

  • data – Observed data

  • init – Initial state

  • num_samples – Number of samples to draw

  • burn_in (int) – Number of samples to discard at the beginning

  • thin (int) – Thinning rate

  • rng_key – Random number generator key

  • savef – Function to save the state

Returns:

List of log likelihoods and samples

hyperiax.mcmc.parameter module

class hyperiax.mcmc.parameter.Parameter(value)

Bases: ABC

Base class for a parameter in a Markov Chain Monte Carlo simulation.

abstract log_prior()

Logarithm of the prior probability of the parameter.

Returns:

The logarithm of the prior probability of the parameter.

abstract propose(key) Parameter

Propose a new parameter given a key

Parameters:

key – the key to generate the parameter with

Returns:

A new parameter proposal

abstract update(value, accepted=True)

Update the value of the parameter, if accepted.

value: The new value of the parameter. accepted: Whether the new value is accepted. Default true.

hyperiax.mcmc.parameterstore module

class hyperiax.mcmc.parameterstore.ParameterStore(params: Dict[str, Parameter])

Bases: object

The parameter store hosts a set of parameters.

log_prior()

Logarithm of the prior probability of the parameters.

Returns:

The logarithm of the prior probability of the parameters.

propose(key) ParameterStore

Propose a new parameter store, containing newly sampled parameters.

Parameters:

key – A key to sample with.

Returns:

The newly sampled parameter store.

values()

Gets the values of the parameters in the store

Returns:

The parameters in a dictionary.

hyperiax.mcmc.plotting module

hyperiax.mcmc.varianceParameter module

class hyperiax.mcmc.varianceParameter.VarianceParameter(value, alpha=3.0, beta=2.0, proposal_var=0.01, keep_constant=False, max=None)

Bases: Parameter

log_prior()

Logarithm of the prior probability of the parameter

Returns:

The logarithm of the prior probability of the parameter

propose(key)

Propose a new value for the parameter

Parameters:

key – A key to sample with

Returns:

The newly proposed parameter

update(value, accepted)

Update the parameter with a new value

Parameters:
  • value – The new value to update the parameter with

  • accepted – Whether the new value was accepted.

hyperiax.mcmc.varianceParameter.inverse_gamma_logpdf(x, alpha, beta)

Log PDF of the inverse gamma distribution

Parameters:
  • x – The value to evaluate the PDF at

  • alpha – The alpha parameter of the inverse gamma distribution

  • beta – The beta parameter of the inverse gamma distribution

Returns:

The logarithm of the PDF of the inverse gamma distribution at x

Module contents