packages feed

mcmc 0.8.0.0 → 0.8.0.1

raw patch · 6 files changed

+60/−40 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

ChangeLog.md view
@@ -5,6 +5,14 @@ ## Unreleased changes  +## 0.8.0.1++-   Improve exception handling (also during execution of monitors; also improve+    the output).+-   Increase maximum tuning parameter.+-   Minor bug fix: acceptance rates are again reported at end of run.++ ## 0.8.0.0  -   Use the new bytestring realfloat builder.
README.md view
@@ -1,4 +1,5 @@ + # Markov chain Monte Carlo sampler  <p align="center"><img src="https://travis-ci.org/dschrempf/mcmc.svg?branch=master"/></p>@@ -7,10 +8,11 @@  At the moment, the following algorithms are available: --   Metropolis-Hastings-Green <sup><a id="fnr.1" class="footref" href="#fn.1" role="doc-backlink">1</a></sup>;+-   Metropolis-Hastings-Green (Geyer, Charles J, 2011); -   Metropolis-coupled Markov chain Monte Carlo (also known as parallel-    tempering) <sup><a id="fnr.2" class="footref" href="#fn.2" role="doc-backlink">2</a></sup> <sup>, </sup><sup><a id="fnr.3" class="footref" href="#fn.3" role="doc-backlink">3</a></sup>.--   Hamilton Monte Carlo proposal <sup><a id="fnr.4" class="footref" href="#fn.4" role="doc-backlink">4</a></sup>.+    tempering) (Geyer, Charles J, 1991,  Altekar, Gautam and Dwarkadas, Sandhya and Huelsenbeck, John P and Ronquist, Fredrik, 2004);+-   Hamilton Monte Carlo proposal (Neal, Radford M, 2011);+-   No U-Turn Sampler (NUTS) (Matthew D. Hoffman and Andrew Gelman, 2014).   ## Documentation@@ -35,18 +37,15 @@ For a more involved example, have a look at a [phylogenetic dating project](https://github.com/dschrempf/mcmc-dating).  -# Footnotes+# References -<sup><a id="fn.1" href="#fnr.1">1</a></sup> Geyer, C. J., Introduction to Markov chain Monte Carlo, In Handbook of-Markov Chain Monte Carlo (pp. 45) (2011). CRC press.+Altekar, Gautam and Dwarkadas, Sandhya and Huelsenbeck, John P and Ronquist, Fredrik (2004). *Parallel metropolis coupled Markov chain Monte Carlo for Bayesian phylogenetic inference*. -<sup><a id="fn.2" href="#fnr.2">2</a></sup> Geyer, C. J., Markov chain monte carlo maximum likelihood, Computing-Science and Statistics, Proceedings of the 23rd Symposium on the Interface,-(1991).+Geyer, Charles J (2011). *{Introduction to Markov Chain Monte Carlo}*, CRC press. -<sup><a id="fn.3" href="#fnr.3">3</a></sup> Altekar, G., Dwarkadas, S., Huelsenbeck, J. P., & Ronquist, F., Parallel-metropolis coupled markov chain monte carlo for bayesian phylogenetic inference,-Bioinformatics, 20(3), 407–415 (2004).+Geyer, Charles J (1991). *Markov chain Monte Carlo maximum likelihood*. -<sup><a id="fn.4" href="#fnr.4">4</a></sup> Neal, R. M., Mcmc Using Hamiltonian Dynamics, In S. Brooks, A. Gelman, G.-Jones, & X. Meng (Eds.), Handbook of Markov Chain Monte Carlo (2011). CRC press.+Matthew D. Hoffman and Andrew Gelman (2014). *The No-U-Turn Sampler: Adaptively Setting Path Lengths in Hamiltonian Monte Carlo*.++Neal, Radford M (2011). *{MCMC Using Hamiltonian Dynamics}*, CRC press.+
mcmc.cabal view
@@ -1,6 +1,6 @@ cabal-version:      3.0 name:               mcmc-version:            0.8.0.0+version:            0.8.0.1 synopsis:           Sample from a posterior using Markov chain Monte Carlo description:   Please see the README on GitHub at <https://github.com/dschrempf/mcmc#readme>
src/Mcmc/Environment.hs view
@@ -25,7 +25,9 @@  -- | The environment of an MCMC run. data Environment s = Environment-  { settings :: s,+  { -- | Use a polymorphic settings variable, because we have 'Settings', but+    -- also 'Mcmc.MarginalLikelihood.MLSettings'.+    settings :: s,     -- | List will be empty if using 'Quiet'. If 'LogStdOutAndFile' is used     -- 'logHandles' contains two handles to the standard output and the log     -- file.
src/Mcmc/Mcmc.hs view
@@ -56,17 +56,16 @@  mcmcExceptionHandler :: Algorithm a => Environment Settings -> a -> AsyncException -> IO b mcmcExceptionHandler e a err = do-  putStrLn ""-  putStrLn "INTERRUPT!"-  putStrLn "Try to terminate gracefully and save chain for continuation."-  putStrLn "Press CTRL-C (again) to terminate now."-  putStrLn "Closing output files."-  _ <- aCloseMonitors a-  closeEnvironment e-  runReaderT (mcmcSave a) e+  _ <- runReaderT action e   putStrLn "Graceful termination successful."-  putStrLn "Rethrowing error."-  throw err+  putStrLn $ "Rethrowing error: " <> displayException err <> "."+  throwIO err+  where+    action = do+      logWarnS "INTERRUPT!"+      logWarnS "Trying to terminate gracefully and to save chain for continuation."+      logWarnS "Press CTRL-C (again) to terminate now."+      mcmcClose a  mcmcExecuteMonitors :: Algorithm a => a -> MCMC () mcmcExecuteMonitors a = do@@ -75,8 +74,7 @@       vb = sVerbosity s       t0 = startingTime e       iTotal = burnInIterations (sBurnIn s) + fromIterations (sIterations s)-  -- NOTE: Mask asynchronous exceptions when writing monitor files.-  mStdLog <- liftIO $ mask_ $ aExecuteMonitors vb t0 iTotal a+  mStdLog <- liftIO $ aExecuteMonitors vb t0 iTotal a   forM_ mStdLog (logOutB "   ")  mcmcIterate :: Algorithm a => IterationMode -> Int -> a -> MCMC a@@ -85,12 +83,24 @@   | n == 0 = return a   | otherwise = do       e <- ask-      p <- sParallelizationMode . settings <$> ask-      -- NOTE: User interrupt is only handled during iterations.-      a' <- liftIO $ catch (aIterate m p a) (mcmcExceptionHandler e a)-      -- NOTE: We may want to mask execution of monitors and catch exceptions-      -- even then?-      mcmcExecuteMonitors a'+      let p = sParallelizationMode $ settings e+      -- NOTE: Handle interrupts during iterations, before writing monitors,+      -- using the old algorithm state @a@.+      let handlerOld = mcmcExceptionHandler e a+          actionIterate = aIterate m p a+      a' <- liftIO $ actionIterate `catch` handlerOld+      -- NOTE: Mask asynchronous exceptions while writing monitor files. Handle+      -- interrupts after writing monitors; use the new state @a'@.+      --+      -- The problem that arises using this method is: What if executing the+      -- monitors actually throws an error (and not the user or the operating+      -- system that want to stop the chain). In this case, the chain is left in+      -- an undefined state because the monitor files are partly written; the+      -- new state is saved by the handler. However, I do not think I can+      -- recover from partly written monitor files.+      let handlerNew = mcmcExceptionHandler e a'+          actionWrite = runReaderT (mcmcExecuteMonitors a') e+      liftIO $ (uninterruptibleMask_ actionWrite) `catch` handlerNew       mcmcIterate m (n - 1) a'  mcmcNewRun :: Algorithm a => a -> MCMC a@@ -233,13 +243,12 @@ -- Report and finish up. mcmcClose :: Algorithm a => a -> MCMC a mcmcClose a = do-  logDebugB "Closing MCMC run."-  logInfoB $ aSummarizeCycle AllProposals a-  logInfoS $ aName a ++ " algorithm finished."-  mcmcSave a-  logInfoEndTime+  logInfoS "Closing monitors."   a' <- liftIO $ aCloseMonitors a+  mcmcSave a'+  logInfoEndTime   e <- ask+  logInfoS "Closing environment."   liftIO $ closeEnvironment e   return a' @@ -258,6 +267,8 @@   a'' <- mcmcExecute a'    -- Close.+  logInfoB $ aSummarizeCycle AllProposals a''+  logInfoS $ aName a'' ++ " algorithm finished."   mcmcClose a''  -- | Run an MCMC algorithm with given settings.
src/Mcmc/Proposal.hs view
@@ -334,7 +334,7 @@  -- | Maximal tuning parameter; subject to change. tuningParameterMax :: TuningParameter-tuningParameterMax = 1e3+tuningParameterMax = 5e3  -- | Tune a 'Proposal'. --