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
This basic Metropolis implementation assumes using symmetric proposal function.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMetropolis
(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
Modifier and TypeMethodDescriptionprotected 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 Details
-
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 Details
-
nextProposedState
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
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
-