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 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 sample
      proposalFunction - 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 algorithm
      uniform - 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 sample
      initialState - the initial state of the algorithm
      sigma - the standard deviation the Normal random vector generated by the proposal distribution
      uniform - 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 sample
      initialState - the initial state of the algorithm
      scale - 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 vector
      uniform - the random long generator to be used. This should be the same RLG that is used in the proposal function.
  • Method Details

    • nextProposedState

      protected Vector nextProposedState(Vector currentState)
      Description copied from class: AbstractMetropolis
      Proposes a next state for the system.
      Specified by:
      nextProposedState in class AbstractMetropolis
      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 class AbstractMetropolis
      Parameters:
      currentState - the current state of the system
      proposedState - the proposed next state of the system
      Returns:
      whether the system should accept the proposed next state