Copyright | (c) Dominik Schrempf 2020 |
---|---|
License | GPL-3.0-or-later |
Maintainer | dominik.schrempf@gmail.com |
Stability | unstable |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Creation date: Wed May 20 13:42:53 2020.
Synopsis
- newtype PName = PName {}
- newtype PDescription = PDescription {}
- newtype PWeight = PWeight {
- fromPWeight :: Int
- data PDimension
- data Proposal a = Proposal {
- pName :: PName
- pDescription :: PDescription
- pDimension :: PDimension
- pWeight :: PWeight
- pSimple :: ProposalSimple a
- pTuner :: Maybe (Tuner a)
- (@~) :: Lens' b a -> Proposal a -> Proposal b
- type ProposalSimple a = a -> GenIO -> IO (a, Log Double, Log Double)
- data Tuner a
- data Tune
- createProposal :: PDescription -> (Double -> ProposalSimple a) -> PDimension -> PName -> PWeight -> Tune -> Proposal a
- tune :: (Double -> Double) -> Proposal a -> Maybe (Proposal a)
- getOptimalRate :: PDimension -> Double
- proposalHeader :: ByteString
- proposalHLine :: ByteString
- summarizeProposal :: PName -> PDescription -> PWeight -> Maybe Double -> PDimension -> Maybe (Int, Int, Double) -> ByteString
- data Order
- data Cycle a
- cycleFromList :: [Proposal a] -> Cycle a
- setOrder :: Order -> Cycle a -> Cycle a
- orderProposals :: Cycle a -> GenIO -> IO [Proposal a]
- tuneCycle :: Map (Proposal a) (Double -> Double) -> Cycle a -> Cycle a
- autoTuneCycle :: Acceptance (Proposal a) -> Cycle a -> Cycle a
- summarizeCycle :: Acceptance (Proposal a) -> Cycle a -> ByteString
- data Acceptance k
- emptyA :: Ord k => [k] -> Acceptance k
- pushA :: Ord k => k -> Bool -> Acceptance k -> Acceptance k
- resetA :: Ord k => Acceptance k -> Acceptance k
- transformKeysA :: (Ord k1, Ord k2) => [k1] -> [k2] -> Acceptance k1 -> Acceptance k2
- acceptanceRate :: Ord k => k -> Acceptance k -> Maybe (Int, Int, Double)
- acceptanceRates :: Acceptance k -> Map k Double
Proposal
Proposal name.
newtype PDescription Source #
Proposal description.
Instances
Eq PDescription Source # | |
Defined in Mcmc.Proposal (==) :: PDescription -> PDescription -> Bool # (/=) :: PDescription -> PDescription -> Bool # | |
Ord PDescription Source # | |
Defined in Mcmc.Proposal compare :: PDescription -> PDescription -> Ordering # (<) :: PDescription -> PDescription -> Bool # (<=) :: PDescription -> PDescription -> Bool # (>) :: PDescription -> PDescription -> Bool # (>=) :: PDescription -> PDescription -> Bool # max :: PDescription -> PDescription -> PDescription # min :: PDescription -> PDescription -> PDescription # | |
Show PDescription Source # | |
Defined in Mcmc.Proposal showsPrec :: Int -> PDescription -> ShowS # show :: PDescription -> String # showList :: [PDescription] -> ShowS # |
The weight determines how often a Proposal
is executed per iteration of
the Markov chain.
data PDimension Source #
Proposal dimension.
The number of affected, independent parameters.
The optimal acceptance rate of low dimensional proposals is higher than for high dimensional ones.
Optimal acceptance rates are still subject to controversies. As far as I
know, research has focused on random walk proposal with a multivariate normal
distribution of dimension d
. In this case, the following acceptance rates
are desired:
- one dimension: 0.44 (numerical results);
- five and more dimensions: 0.234 (numerical results);
- infinite dimensions: 0.234 (theorem for specific target distributions).
See Handbook of Markov chain Monte Carlo, chapter 4.
Of course, many proposals may not be classical random walk proposals. For
example, the beta proposal on a simplex (beta
)
samples one new variable of the simplex from a beta distribution while
rescaling all other variables. What is the dimension of this proposal? I
don't know, but I set the dimension to 2. The reason is that if the dimension
of the simplex is 2, two variables are changed. If the dimension of the
simplex is high, one variable is changed substantially, while all others are
changed marginally.
Further, if a proposal changes a number of variables in the same way (and not independently like in a random walk proposal), I still set the dimension of the proposal to the number of variables changed.
Finally, I assume that proposals of unknown dimension have high dimension, and use the optimal acceptance rate 0.234.
A Proposal
is an instruction about how the Markov chain will traverse the
state space a
. Essentially, it is a probability mass or probability density
conditioned on the current state (i.e., a Markov kernel).
A Proposal
may be tuneable in that it contains information about how to enlarge
or shrink the step size to tune the acceptance rate.
Proposal | |
|
Instances
Eq (Proposal a) Source # | |
Ord (Proposal a) Source # | |
(@~) :: Lens' b a -> Proposal a -> Proposal b Source #
Convert a proposal from one data type to another using a lens.
For example:
scaleFirstEntryOfTuple = _1 @~ scale
type ProposalSimple a = a -> GenIO -> IO (a, Log Double, Log Double) Source #
Simple proposal without tuning information.
Instruction about randomly moving from the current state to a new state, given some source of randomness.
In order to calculate the Metropolis-Hastings-Green ratio, we need to know the ratio of the backward to forward kernels (i.e., the probability masses or probability densities) and the absolute value of the determinant of the Jacobian matrix.
For unbiased proposals, these values are 1.0 such that
proposalSimpleUnbiased x g = return (x', 1.0, 1.0)
For biased proposals, the kernel ratio is qYX / qXY, where qXY is the probability density to move from X to Y, and the absolute value of the determinant of the Jacobian matrix differs from 1.0.
Tune the proposal?
:: PDescription | Description of the proposal type and parameters. |
-> (Double -> ProposalSimple a) | Function creating a simple proposal for a given tuning parameter. The larger the tuning parameter, the larger the proposal (and the lower the expected acceptance rate), and vice versa. |
-> PDimension | Dimension. |
-> PName | Name. |
-> PWeight | Weight. |
-> Tune | Activate tuning? |
-> Proposal a |
Create a tuneable proposal.
getOptimalRate :: PDimension -> Double Source #
See PDimension
.
proposalHeader :: ByteString Source #
Header of proposal summaries.
proposalHLine :: ByteString Source #
Horizontal line of proposal summaries.
summarizeProposal :: PName -> PDescription -> PWeight -> Maybe Double -> PDimension -> Maybe (Int, Int, Double) -> ByteString Source #
Proposal summary.
Cycle
Define the order in which Proposal
s are executed in a Cycle
. The total
number of Proposal
s per Cycle
may differ between Order
s (e.g., compare
RandomO
and RandomReversibleO
).
RandomO | Shuffle the |
SequentialO | The |
RandomReversibleO | Similar to |
SequentialReversibleO | Similar to |
In brief, a Cycle
is a list of proposals.
The state of the Markov chain will be logged only after all Proposal
s in
the Cycle
have been completed, and the iteration counter will be increased
by one. The order in which the Proposal
s are executed is specified by
Order
. The default is RandomO
.
No proposals with the same name and description are allowed in a Cycle
, so
that they can be uniquely identified.
orderProposals :: Cycle a -> GenIO -> IO [Proposal a] Source #
Replicate Proposal
s according to their weights and possibly shuffle them.
autoTuneCycle :: Acceptance (Proposal a) -> Cycle a -> Cycle a Source #
summarizeCycle :: Acceptance (Proposal a) -> Cycle a -> ByteString Source #
Acceptance
data Acceptance k Source #
For each key k
, store the number of accepted and rejected proposals.
Instances
Eq k => Eq (Acceptance k) Source # | |
Defined in Mcmc.Proposal (==) :: Acceptance k -> Acceptance k -> Bool # (/=) :: Acceptance k -> Acceptance k -> Bool # | |
(Ord k, Read k) => Read (Acceptance k) Source # | |
Defined in Mcmc.Proposal readsPrec :: Int -> ReadS (Acceptance k) # readList :: ReadS [Acceptance k] # readPrec :: ReadPrec (Acceptance k) # readListPrec :: ReadPrec [Acceptance k] # | |
Show k => Show (Acceptance k) Source # | |
Defined in Mcmc.Proposal showsPrec :: Int -> Acceptance k -> ShowS # show :: Acceptance k -> String # showList :: [Acceptance k] -> ShowS # | |
ToJSONKey k => ToJSON (Acceptance k) Source # | |
Defined in Mcmc.Proposal toJSON :: Acceptance k -> Value # toEncoding :: Acceptance k -> Encoding # toJSONList :: [Acceptance k] -> Value # toEncodingList :: [Acceptance k] -> Encoding # | |
(Ord k, FromJSONKey k) => FromJSON (Acceptance k) Source # | |
Defined in Mcmc.Proposal parseJSON :: Value -> Parser (Acceptance k) # parseJSONList :: Value -> Parser [Acceptance k] # |
emptyA :: Ord k => [k] -> Acceptance k Source #
In the beginning there was the Word.
Initialize an empty storage of accepted/rejected values.
pushA :: Ord k => k -> Bool -> Acceptance k -> Acceptance k Source #
For key k
, prepend an accepted (True) or rejected (False) proposal.
resetA :: Ord k => Acceptance k -> Acceptance k Source #
Reset acceptance storage.
transformKeysA :: (Ord k1, Ord k2) => [k1] -> [k2] -> Acceptance k1 -> Acceptance k2 Source #
Transform keys using the given lists. Keys not provided will not be present
in the new Acceptance
variable.
acceptanceRate :: Ord k => k -> Acceptance k -> Maybe (Int, Int, Double) Source #
Acceptance counts and rate for a specific proposal.
acceptanceRates :: Acceptance k -> Map k Double Source #
Acceptance rates for all proposals.