Class Metropolis
- java.lang.Object
-
- dev.nm.stat.random.rng.multivariate.mcmc.metropolis.AbstractMetropolis
-
- dev.nm.stat.random.rng.multivariate.mcmc.metropolis.Metropolis
-
- All Implemented Interfaces:
RandomVectorGenerator
,Seedable
public class Metropolis extends AbstractMetropolis
This basic Metropolis implementation assumes using symmetric proposal function.- See Also:
- Wikipedia on Metropolis-Hastings
- Roberts, G. O., Gelman, A., Gilks, W. R. "Weak convergence and optimal scaling of random walk Metropolis algorithms," Ann. Appl. Probab. 1997.
- Liu, Jun S. "Ch.5.1, The Metropolis Algorithm (p.106-107 in pdf)," Monte Carlo Strategies in Scientific Computing. 2002.
-
-
Constructor Summary
Constructors Constructor Description Metropolis(RealScalarFunction logf, Vector initialState, double sigma, RandomLongGenerator uniform)
Constructs a new instance, which draws the offset of the next proposed state from the previous state from a standard Normal distribution, with the given variance and zero covariance.Metropolis(RealScalarFunction logf, Vector initialState, Matrix scale, RandomLongGenerator uniform)
Constructs a new instance, which draws the offset of the next proposed state from the previous state from a standard Normal distribution, multiplied by the given scale matrix.Metropolis(RealScalarFunction logf, RealVectorFunction proposalFunction, Vector initialState, RandomLongGenerator uniform)
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 currentState, Vector proposedState)
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
-
Metropolis
public Metropolis(RealScalarFunction logf, RealVectorFunction proposalFunction, Vector initialState, RandomLongGenerator uniform)
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 state. This function MUST be symmetric about it's input argument for the algorithm to converge.initialState
- the initial state of the algorithmuniform
- the random long generator to be used. This should be the same RLG that is used in the proposal function.
-
Metropolis
public Metropolis(RealScalarFunction logf, Vector initialState, double sigma, RandomLongGenerator uniform)
Constructs a new instance, which draws the offset of the next proposed state from the previous state from a standard Normal distribution, with the given variance and zero covariance.- Parameters:
logf
- the log of the unnormalized pdf from which we wish to sampleinitialState
- the initial state of the algorithmsigma
- the standard deviation the Normal random vector generated by the proposal distributionuniform
- the random long generator to be used. This should be the same RLG that is used in the proposal function.
-
Metropolis
public Metropolis(RealScalarFunction logf, Vector initialState, Matrix scale, RandomLongGenerator uniform)
Constructs a new instance, which draws the offset of the next proposed state from the previous state from a standard Normal distribution, multiplied by the given scale matrix.- Parameters:
logf
- the log of the unnormalized pdf from which we wish to sampleinitialState
- the initial state of the algorithmscale
- the square root of the covariance matrix, where the next proposal is computed by x+scale*z, where x is the previous proposal and z is a standard Normal random vectoruniform
- the random long generator to be used. This should be the same RLG that is used in the proposal function.
-
-
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 currentState, Vector proposedState)
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:
currentState
- the current state of the systemproposedState
- the proposed next state of the system- Returns:
- whether the system should accept the proposed next state
-
-