Class MetropolisHastings
- java.lang.Object
-
- dev.nm.stat.random.rng.multivariate.mcmc.metropolis.AbstractMetropolis
-
- dev.nm.stat.random.rng.multivariate.mcmc.metropolis.MetropolisHastings
-
- All Implemented Interfaces:
RandomVectorGenerator
,Seedable
public class MetropolisHastings extends AbstractMetropolis
A generalization of the Metropolis algorithm, which allows asymmetric proposal functions.- See Also:
- Wikipedia: Metropolis-Hastings
- Liu, Jun S. "Ch.5.1, The Metropolis Algorithm (p.106-107 in pdf)," Monte Carlo Strategies in Scientific Computing. 2002.
- Matlab's mhsample
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
MetropolisHastings.ProposalDensityFunction
Defines the density of a proposal function, i.e.
-
Constructor Summary
Constructors Constructor Description MetropolisHastings(RealScalarFunction logf, ProposalFunction proposalFunction, MetropolisHastings.ProposalDensityFunction proposalDensity, Vector initialState, RandomNumberGenerator rng)
Constructs a new instance with the given parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
isProposalAccepted(Vector x, Vector y)
Decides whether the given proposed state should be accepted, or whether the system should remain in it's current state.protected Vector
nextProposedState(Vector currentState)
Proposes a next state for the system.-
Methods inherited from class dev.nm.stat.random.rng.multivariate.mcmc.metropolis.AbstractMetropolis
acceptanceRate, nextVector, seed
-
-
-
-
Constructor Detail
-
MetropolisHastings
public MetropolisHastings(RealScalarFunction logf, ProposalFunction proposalFunction, MetropolisHastings.ProposalDensityFunction proposalDensity, Vector initialState, RandomNumberGenerator rng)
Constructs a new instance with the given parameters.- Parameters:
logf
- the log of the unnormalized pdf from which we wish to sampleproposalFunction
- generates a proposal for the next state, given the current stateproposalDensity
- the proposal density (see explanation in MetropolisHastings.ProposalDensityFunction)initialState
- the initial state of the algorithmrng
- a random number generator
-
-
Method Detail
-
nextProposedState
protected Vector nextProposedState(Vector currentState)
Description copied from class:AbstractMetropolis
Proposes a next state for the system.- Specified by:
nextProposedState
in classAbstractMetropolis
- Parameters:
currentState
- the current state of the system- Returns:
- the proposed next state
-
isProposalAccepted
protected boolean isProposalAccepted(Vector x, Vector y)
Description copied from class:AbstractMetropolis
Decides whether the given proposed state should be accepted, or whether the system should remain in it's current state.- Specified by:
isProposalAccepted
in classAbstractMetropolis
- Parameters:
x
- the current state of the systemy
- the proposed next state of the system- Returns:
- whether the system should accept the proposed next state
-
-