Hello community,
here is the log from the commit of package ghc-mighty-metropolis for
openSUSE:Factory checked in at 2017-03-03 17:51:07
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/ghc-mighty-metropolis (Old)
and /work/SRC/openSUSE:Factory/.ghc-mighty-metropolis.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-mighty-metropolis"
Fri Mar 3 17:51:07 2017 rev:4 rq:461661 version:1.2.0
Changes:
--------
---
/work/SRC/openSUSE:Factory/ghc-mighty-metropolis/ghc-mighty-metropolis.changes
2017-01-12 15:50:32.904313319 +0100
+++
/work/SRC/openSUSE:Factory/.ghc-mighty-metropolis.new/ghc-mighty-metropolis.changes
2017-03-03 17:51:08.289161012 +0100
@@ -1,0 +2,5 @@
+Sun Feb 12 14:19:28 UTC 2017 - [email protected]
+
+- Update to version 1.2.0 with cabal2obs.
+
+-------------------------------------------------------------------
Old:
----
mighty-metropolis-1.0.4.tar.gz
New:
----
mighty-metropolis-1.2.0.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ ghc-mighty-metropolis.spec ++++++
--- /var/tmp/diff_new_pack.Y0c74n/_old 2017-03-03 17:51:09.345011888 +0100
+++ /var/tmp/diff_new_pack.Y0c74n/_new 2017-03-03 17:51:09.349011322 +0100
@@ -1,7 +1,7 @@
#
# spec file for package ghc-mighty-metropolis
#
-# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
+# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -19,7 +19,7 @@
%global pkg_name mighty-metropolis
%bcond_with tests
Name: ghc-%{pkg_name}
-Version: 1.0.4
+Version: 1.2.0
Release: 0
Summary: The Metropolis algorithm
License: MIT
@@ -27,6 +27,7 @@
Url: https://hackage.haskell.org/package/%{pkg_name}
Source0:
https://hackage.haskell.org/package/%{pkg_name}-%{version}/%{pkg_name}-%{version}.tar.gz
BuildRequires: ghc-Cabal-devel
+BuildRequires: ghc-kan-extensions-devel
BuildRequires: ghc-mcmc-types-devel
BuildRequires: ghc-mwc-probability-devel
BuildRequires: ghc-pipes-devel
@@ -44,8 +45,9 @@
Wander around parameter space according to a simple spherical Gaussian
distribution.
-Exports a 'mcmc' function that prints a trace to stdout, as well as a
-'metropolis' transition operator that can be used more generally.
+Exports a 'mcmc' function that prints a trace to stdout, a 'chain' function for
+collecting results in-memory, and a 'metropolis' transition operator that can
+be used more generally.
> import Numeric.MCMC.Metropolis > > rosenbrock :: [Double] -> Double >
rosenbrock [x0, x1] = negate (5 *(x1 - x0 ^ 2) ^ 2 + 0.05 * (1 - x0) ^ 2) > >
++++++ mighty-metropolis-1.0.4.tar.gz -> mighty-metropolis-1.2.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/mighty-metropolis-1.0.4/Numeric/MCMC/Metropolis.hs
new/mighty-metropolis-1.2.0/Numeric/MCMC/Metropolis.hs
--- old/mighty-metropolis-1.0.4/Numeric/MCMC/Metropolis.hs 2016-10-31
21:16:01.000000000 +0100
+++ new/mighty-metropolis-1.2.0/Numeric/MCMC/Metropolis.hs 2016-12-21
21:26:21.000000000 +0100
@@ -21,6 +21,7 @@
module Numeric.MCMC.Metropolis (
mcmc
+ , chain
, metropolis
-- * Re-exported
@@ -31,15 +32,17 @@
, MWC.asGenIO
) where
-import Control.Monad (when)
-import Control.Monad.Primitive (PrimMonad, PrimState, RealWorld)
+import Control.Monad (when, replicateM)
+import Control.Monad.Codensity (lowerCodensity)
+import Control.Monad.Primitive (PrimMonad, PrimState)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.State.Strict (execStateT, get, put)
+import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.Sampling.Types (Target(..), Chain(..), Transition)
#if __GLASGOW_HASKELL__ < 710
import Data.Traversable (Traversable, traverse)
#endif
-import Pipes (Producer, yield, (>->), runEffect)
+import Pipes (Producer, Consumer, yield, (>->), runEffect, await)
import qualified Pipes.Prelude as Pipes (mapM_, take)
import System.Random.MWC.Probability (Gen, Prob)
import qualified System.Random.MWC.Probability as MWC
@@ -68,19 +71,52 @@
accept <- lift (MWC.bernoulli acceptProb)
when accept (put (Chain chainTarget proposalScore proposal chainTunables))
--- A Markov chain driven by the Metropolis transition operator.
-chain
+-- Drive a Markov chain via the Metropolis transition operator.
+drive
:: (Traversable f, PrimMonad m)
=> Double
-> Chain (f Double) b
-> Gen (PrimState m)
- -> Producer (Chain (f Double) b) m ()
-chain radial = loop where
+ -> Producer (Chain (f Double) b) m c
+drive radial = loop where
loop state prng = do
next <- lift (MWC.sample (execStateT (metropolis radial) state) prng)
yield next
loop next prng
+-- | Trace 'n' iterations of a Markov chain and collect the results in a list.
+--
+-- >>> let rosenbrock [x0, x1] = negate (5 *(x1 - x0 ^ 2) ^ 2 + 0.05 * (1 -
x0) ^ 2)
+-- >>> results <- withSystemRandom . asGenIO $ chain 3 1 [0, 0] rosenbrock
+-- >>> mapM_ print results
+-- 0.0,0.0
+-- 1.4754117657794871e-2,0.5033208261760778
+-- 3.8379699517007895e-3,0.24627131099479127
+chain
+ :: (PrimMonad m, Traversable f)
+ => Int
+ -> Double
+ -> f Double
+ -> (f Double -> Double)
+ -> Gen (PrimState m)
+ -> m [Chain (f Double) b]
+chain n radial position target gen = runEffect $
+ drive radial origin gen
+ >-> collect n
+ where
+ ctarget = Target target Nothing
+
+ origin = Chain {
+ chainScore = lTarget ctarget position
+ , chainTunables = Nothing
+ , chainTarget = ctarget
+ , chainPosition = position
+ }
+
+ collect :: Monad m => Int -> Consumer a m [a]
+ collect size = lowerCodensity $
+ replicateM size (lift Pipes.await)
+
-- | Trace 'n' iterations of a Markov chain and stream them to stdout.
--
-- >>> let rosenbrock [x0, x1] = negate (5 *(x1 - x0 ^ 2) ^ 2 + 0.05 * (1 -
x0) ^ 2)
@@ -89,17 +125,17 @@
-- 0.5000462419822702,0.5693944056267897
-- -0.7525995304580824,1.2240725505283248
mcmc
- :: (Traversable f, Show (f Double))
+ :: (MonadIO m, PrimMonad m, Traversable f, Show (f Double))
=> Int
-> Double
-> f Double
-> (f Double -> Double)
- -> Gen RealWorld
- -> IO ()
+ -> Gen (PrimState m)
+ -> m ()
mcmc n radial chainPosition target gen = runEffect $
- chain radial Chain {..} gen
+ drive radial Chain {..} gen
>-> Pipes.take n
- >-> Pipes.mapM_ print
+ >-> Pipes.mapM_ (liftIO . print)
where
chainScore = lTarget chainTarget chainPosition
chainTunables = Nothing
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/mighty-metropolis-1.0.4/mighty-metropolis.cabal
new/mighty-metropolis-1.2.0/mighty-metropolis.cabal
--- old/mighty-metropolis-1.0.4/mighty-metropolis.cabal 2016-12-04
09:57:54.000000000 +0100
+++ new/mighty-metropolis-1.2.0/mighty-metropolis.cabal 2016-12-21
21:12:01.000000000 +0100
@@ -1,5 +1,5 @@
name: mighty-metropolis
-version: 1.0.4
+version: 1.2.0
synopsis: The Metropolis algorithm.
homepage: http://github.com/jtobin/mighty-metropolis
license: MIT
@@ -15,8 +15,9 @@
Wander around parameter space according to a simple spherical Gaussian
distribution.
.
- Exports a 'mcmc' function that prints a trace to stdout, as well as a
- 'metropolis' transition operator that can be used more generally.
+ Exports a 'mcmc' function that prints a trace to stdout, a 'chain' function
+ for collecting results in-memory, and a 'metropolis' transition operator that
+ can be used more generally.
.
> import Numeric.MCMC.Metropolis
>
@@ -38,6 +39,7 @@
Numeric.MCMC.Metropolis
build-depends:
base >= 4 && < 6
+ , kan-extensions >= 5 && < 6
, pipes >= 4 && < 5
, primitive >= 0.6 && < 1.0
, mcmc-types >= 1.0.1
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/mighty-metropolis-1.0.4/test/BNN.hs
new/mighty-metropolis-1.2.0/test/BNN.hs
--- old/mighty-metropolis-1.0.4/test/BNN.hs 2016-10-31 21:17:26.000000000
+0100
+++ new/mighty-metropolis-1.2.0/test/BNN.hs 2016-12-21 21:09:20.000000000
+0100
@@ -11,5 +11,7 @@
x1 = index xs 1
main :: IO ()
-main = withSystemRandom . asGenIO $ mcmc 100 1 (fromList [0, 0]) bnn
+main = withSystemRandom . asGenIO $ \gen -> do
+ _ <- chain 50 1 (fromList [0, 0]) bnn gen
+ mcmc 50 1 (fromList [0, 0]) bnn gen
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/mighty-metropolis-1.0.4/test/Rosenbrock.hs
new/mighty-metropolis-1.2.0/test/Rosenbrock.hs
--- old/mighty-metropolis-1.0.4/test/Rosenbrock.hs 2016-10-31
21:17:32.000000000 +0100
+++ new/mighty-metropolis-1.2.0/test/Rosenbrock.hs 2016-12-21
21:10:16.000000000 +0100
@@ -8,5 +8,7 @@
rosenbrock [x0, x1] = negate (5 *(x1 - x0 ^ 2) ^ 2 + 0.05 * (1 - x0) ^ 2)
main :: IO ()
-main = withSystemRandom . asGenIO $ mcmc 100 1 [0, 0] rosenbrock
+main = withSystemRandom . asGenIO $ \gen -> do
+ _ <- chain 50 1 [0, 0] rosenbrock gen
+ mcmc 50 1 [0, 0] rosenbrock gen