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
A generalization of the Metropolis algorithm, which allows asymmetric proposal
functions.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Defines the density of a proposal function, i.e. -
Constructor Summary
ConstructorsConstructorDescriptionMetropolisHastings
(RealScalarFunction logf, ProposalFunction proposalFunction, MetropolisHastings.ProposalDensityFunction proposalDensity, Vector initialState, RandomNumberGenerator rng) Constructs a new instance with the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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 Details
-
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 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:
x
- the current state of the systemy
- the proposed next state of the system- Returns:
- whether the system should accept the proposed next state
-