beanmachine.ppl.inference.proposer.nmc package

Submodules

Module contents

class beanmachine.ppl.inference.proposer.nmc.SingleSiteHalfSpaceNMCProposer(node: beanmachine.ppl.model.rv_identifier.RVIdentifier)

Bases: beanmachine.ppl.inference.proposer.single_site_ancestral_proposer.SingleSiteAncestralProposer

Single-Site Half Space Newtonian Monte Carlo Proposers. See sec. 3.2 of [1]

[1] Arora, Nim, et al. Newtonian Monte Carlo: single-site MCMC meets second-order gradient methods

compute_alpha_beta(world: beanmachine.ppl.world.world.World) Tuple[bool, torch.Tensor, torch.Tensor]
Computes alpha and beta of the Gamma proposal given the node.

alpha = 1 - hessian_diag * x^2 beta = -1 * x * hessian_diag - first_grad

get_proposal_distribution(world: beanmachine.ppl.world.world.World) torch.distributions.distribution.Distribution

Returns the proposal distribution of the node.

Parameters

world – the world in which we’re proposing a new value for node.

Returns

The proposal distribution.

class beanmachine.ppl.inference.proposer.nmc.SingleSiteRealSpaceNMCProposer(node: beanmachine.ppl.model.rv_identifier.RVIdentifier, alpha: float = 10.0, beta: float = 1.0)

Bases: beanmachine.ppl.inference.proposer.single_site_ancestral_proposer.SingleSiteAncestralProposer

Single-Site Real Space Newtonian Monte Carlo Proposer See sec. 3.1 of [1]

[1] Arora, Nim, et al. Newtonian Monte Carlo: single-site MCMC meets second-order gradient methods

compute_beta_priors_from_accepted_lr(max_lr_num: int = 5) Tuple[torch.Tensor, torch.Tensor]

Compute Alpha and Beta using Method of Moments.

do_adaptation(world: beanmachine.ppl.world.world.World, accept_log_prob: torch.Tensor, is_accepted: bool = False, *args, **kwargs) None

Do adaption based on the learning rates.

Parameters
  • world – the world in which we’re operating in.

  • accept_log_prob – Current accepted log prob (Not used in this particular proposer).

  • is_accepted – bool representing whether the new value was accepted.

get_proposal_distribution(world: beanmachine.ppl.world.world.World) torch.distributions.distribution.Distribution

Returns the proposal distribution of the node.

Parameters

world – the world in which we’re proposing a new value for node required to find a proposal distribution which in this case is the fraction of distance between the current value and NMC mean that we’re going to pick as our proposer mean.

Returns

The proposal distribution.

class beanmachine.ppl.inference.proposer.nmc.SingleSiteSimplexSpaceNMCProposer(node: beanmachine.ppl.model.rv_identifier.RVIdentifier, transform: torch.distributions.transforms.Transform = ComposeTransform())

Bases: beanmachine.ppl.inference.proposer.single_site_ancestral_proposer.SingleSiteAncestralProposer

Single-Site Simplex Newtonian Monte Carlo Proposer See sec. 3.2 of [1]

[1] Arora, Nim, et al. Newtonian Monte Carlo: single-site MCMC meets second-order gradient methods

compute_alpha(world: beanmachine.ppl.world.world.World, min_alpha_value: float = 0.001) Tuple[bool, torch.Tensor]
Computes alpha of the Dirichlet proposal given the node.
alpha = 1 - (x^2) (hessian[i, i] - max(hessian[i]))

where max(hessian[i]) is maximum of the hessian at ith row excluding the diagonal values.

Parameters

node_var – the node Variable we’re proposing a new value for

Returns

alpha of the Dirichlet distribution as proposal distribution

get_proposal_distribution(world: beanmachine.ppl.world.world.World) torch.distributions.distribution.Distribution

Returns the proposal distribution of the node.

Parameters

world – the world in which we’re proposing a new value for node.

Returns

The proposal distribution.