mixle.inference.mcmc.proposals moduleΒΆ

Proposal kernels for Metropolis-Hastings samplers.

class Proposal[source]

Bases: object

Base proposal protocol for Metropolis-Hastings kernels.

sample(current, rng)[source]

Draw a proposed state given the current state.

Parameters:
Return type:

Any

log_density(proposed, current)[source]

Return log q(proposed | current) for Hastings correction.

Parameters:
  • proposed (Any)

  • current (Any)

Return type:

float

adapt(current, proposed, accepted, step, in_burn_in)[source]

Optional adaptation hook called after each transition.

Parameters:
Return type:

None

class RandomWalkProposal(scale)[source]

Bases: Proposal

Symmetric Gaussian random-walk proposal for scalar/vector states.

Parameters:

scale (Any)

sample(current, rng)[source]

Draw a Gaussian random-walk proposal centered at current.

Parameters:
Return type:

Any

log_density(proposed, current)[source]

Return the Gaussian random-walk transition log density.

Parameters:
  • proposed (Any)

  • current (Any)

Return type:

float

class AdaptiveRandomWalkProposal(scale, target_acceptance=0.44, adaptation_rate=0.05, adapt_during_burn_in_only=True, min_scale=1.0e-12, max_scale=1.0e12)[source]

Bases: RandomWalkProposal

Gaussian random walk with Robbins-Monro scale adaptation.

By default adaptation only runs during burn-in, which preserves the stationary post-burn chain used for retained samples.

Parameters:
  • scale (Any)

  • target_acceptance (float)

  • adaptation_rate (float)

  • adapt_during_burn_in_only (bool)

  • min_scale (float)

  • max_scale (float)

adapt(current, proposed, accepted, step, in_burn_in)[source]

Adjust the random-walk scale toward the target acceptance rate.

Parameters:
Return type:

None

class AdaptiveCovarianceProposal(initial_covariance=1.0, scale=None, regularization=1.0e-6, adapt_after=2, adapt_during_burn_in_only=True)[source]

Bases: Proposal

Full-covariance Gaussian random walk with burn-in covariance learning.

Parameters:
  • initial_covariance (Any)

  • scale (float | None)

  • regularization (float)

  • adapt_after (int)

  • adapt_during_burn_in_only (bool)

sample(current, rng)[source]

Draw a full-covariance Gaussian random-walk proposal.

Parameters:
Return type:

Any

log_density(proposed, current)[source]

Return the current adaptive Gaussian proposal log density.

Parameters:
  • proposed (Any)

  • current (Any)

Return type:

float

adapt(current, proposed, accepted, step, in_burn_in)[source]

Update the empirical covariance estimate during adaptation.

Parameters:
Return type:

None

class IndependentProposal(sampler, log_density=None)[source]

Bases: Proposal

Independence proposal from a sampler plus optional log density.

Parameters:
  • sampler (Callable[[np.random.RandomState], Any])

  • log_density (Callable[[Any], float] | None)

sample(current, rng)[source]

Draw a state independent of current from the supplied sampler.

Parameters:
Return type:

Any

log_density(proposed, current)[source]

Return the proposal log density when one was supplied.

Parameters:
  • proposed (Any)

  • current (Any)

Return type:

float

class MixtureProposal(proposals, weights=None)[source]

Bases: Proposal

Mixture of proposal kernels with exact mixture proposal density.

Parameters:
  • proposals (Sequence[Proposal])

  • weights (Sequence[float] | None)

sample(current, rng)[source]

Draw from one mixture component proposal and remember its index.

Parameters:
Return type:

Any

log_density(proposed, current)[source]

Return the log mixture density of all component proposals.

Parameters:
  • proposed (Any)

  • current (Any)

Return type:

float

adapt(current, proposed, accepted, step, in_burn_in)[source]

Forward adaptation to the component used for the last proposal.

Parameters:
Return type:

None

class BlockProposal(keys, proposal)[source]

Bases: Proposal

Lift a proposal on one or more mapping fields to a full-record proposal.

Parameters:
  • keys (Any)

  • proposal (Proposal)

sample(current, rng)[source]

Propose a replacement for the configured mapping field block.

Parameters:
Return type:

dict[Any, Any]

log_density(proposed, current)[source]

Return the block proposal density inside the full mapping state.

Parameters:
Return type:

float

adapt(current, proposed, accepted, step, in_burn_in)[source]

Forward adaptation to the wrapped block proposal.

Parameters:
Return type:

None

class LangevinProposal(step_size, grad_log_target)[source]

Bases: Proposal

Metropolis-adjusted Langevin proposal for scalar/vector states.

Parameters:
  • step_size (float)

  • grad_log_target (Callable[[Any], Any])

sample(current, rng)[source]

Draw a MALA proposal centered at the Langevin drift mean.

Parameters:
Return type:

Any

log_density(proposed, current)[source]

Return the asymmetric Langevin proposal log density.

Parameters:
  • proposed (Any)

  • current (Any)

Return type:

float