mcmc-types (empty) → 1.0.0
raw patch · 4 files changed
+126/−0 lines, 4 filesdep +basedep +containersdep +mwc-probabilitysetup-changed
Dependencies added: base, containers, mwc-probability, transformers
Files
- Data/Sampling/Types.hs +67/−0
- LICENSE +20/−0
- Setup.hs +2/−0
- mcmc-types.cabal +37/−0
+ Data/Sampling/Types.hs view
@@ -0,0 +1,67 @@+{-# OPTIONS_GHC -Wall #-}+{-# LANGUAGE RecordWildCards #-}++-- |+-- Module: Data.Sampling.Types+-- Copyright: (c) 2015 Jared Tobin+-- License: MIT+--+-- Maintainer: Jared Tobin <jared@jtobin.ca>+-- Stability: unstable+-- Portability: ghc+--+-- Common types for implementing Markov Chain Monte Carlo (MCMC) algorithms.+--+-- 'Target' is a product type intended to hold a log-target density function and+-- potentially its gradient.+--+-- The 'Chain' type represents a kind of annotated parameter space.+-- Technically all that's required here is the type of the parameter space+-- itself (held here in 'chainPosition') but in practice some additional+-- information is typically useful. Additionally there is 'chainScore' for+-- holding the most recent score of the chain, as well as the target itself for+-- implementing things like annealing. The `chainTunables` field can be used+-- to hold arbitrary data.+--+-- One should avoid exploiting these features to do something nasty (like, say,+-- invalidating the Markov property).+--+-- The 'Transition' type permits probabilistic transitions over some state+-- space by way of the underlying 'Prob' monad.++module Data.Sampling.Types (+ Transition+ , Chain(..)+ , Target(..)+ ) where++import Control.Monad.Trans.State.Strict (StateT)+import System.Random.MWC.Probability (Prob)++-- | A generic transition operator.+--+-- Has access to randomness via the underlying 'Prob' monad.+type Transition m a = StateT a (Prob m) ()++-- | The @Chain@ type specifies the state of a Markov chain at any given+-- iteration.+data Chain a b = Chain {+ chainTarget :: Target a+ , chainScore :: !Double+ , chainPosition :: a+ , chainTunables :: Maybe b+ }++instance Show a => Show (Chain a b) where+ show Chain {..} = filter (`notElem` "fromList []") (show chainPosition)++-- | A @Target@ consists of a function from parameter space to the reals, as+-- well as possibly a gradient.+--+-- Most implementations assume a /log/-target, so records are named+-- accordingly.+data Target a = Target {+ lTarget :: a -> Double+ , glTarget :: Maybe (a -> a)+ }+
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2015 Jared Tobin++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ mcmc-types.cabal view
@@ -0,0 +1,37 @@+name: mcmc-types+version: 1.0.0+synopsis: Common types for sampling.+homepage: http://github.com/jtobin/mcmc-types+license: MIT+license-file: LICENSE+author: Jared Tobin+maintainer: jared@jtobin.ca+build-type: Simple+cabal-version: >= 1.18+description:+ Common types for implementing Markov Chain Monte Carlo (MCMC) algorithms.+ .+ An instance of an MCMC problem can be characterized by the following:+ .+ * A /target distribution/ over some parameter space+ .+ * A /parameter space/ for a Markov chain to wander over+ .+ * A /transition operator/ to drive the Markov chain+ .+ /mcmc-types/ provides the suitably-general 'Target', 'Chain', and+ 'Transition' types for representing these things respectively.++Source-repository head+ Type: git+ Location: http://github.com/jtobin/mcmc-types.git++library+ exposed-modules: Data.Sampling.Types+ default-language: Haskell2010+ build-depends:+ base < 5+ , containers+ , mwc-probability >= 1.0.0+ , transformers+