Hello community,
here is the log from the commit of package ghc-hasty-hamiltonian for
openSUSE:Factory checked in at 2017-03-03 17:50:23
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/ghc-hasty-hamiltonian (Old)
and /work/SRC/openSUSE:Factory/.ghc-hasty-hamiltonian.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-hasty-hamiltonian"
Fri Mar 3 17:50:23 2017 rev:4 rq:461634 version:1.3.0
Changes:
--------
---
/work/SRC/openSUSE:Factory/ghc-hasty-hamiltonian/ghc-hasty-hamiltonian.changes
2017-01-12 15:49:30.405142046 +0100
+++
/work/SRC/openSUSE:Factory/.ghc-hasty-hamiltonian.new/ghc-hasty-hamiltonian.changes
2017-03-03 17:50:24.639325892 +0100
@@ -1,0 +2,5 @@
+Sun Feb 12 14:12:34 UTC 2017 - [email protected]
+
+- Update to version 1.3.0 with cabal2obs.
+
+-------------------------------------------------------------------
Old:
----
hasty-hamiltonian-1.1.5.tar.gz
New:
----
hasty-hamiltonian-1.3.0.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ ghc-hasty-hamiltonian.spec ++++++
--- /var/tmp/diff_new_pack.irwDah/_old 2017-03-03 17:50:25.119258110 +0100
+++ /var/tmp/diff_new_pack.irwDah/_new 2017-03-03 17:50:25.119258110 +0100
@@ -1,7 +1,7 @@
#
# spec file for package ghc-hasty-hamiltonian
#
-# 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 hasty-hamiltonian
%bcond_with tests
Name: ghc-%{pkg_name}
-Version: 1.1.5
+Version: 1.3.0
Release: 0
Summary: Speedy traversal through parameter space
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-lens-devel
BuildRequires: ghc-mcmc-types-devel
BuildRequires: ghc-mwc-probability-devel
@@ -50,8 +51,9 @@
<https://hackage.haskell.org/package/ad ad> library for automatic
differentiation.
-Exports a 'mcmc' function that prints a trace to stdout, as well as a
-'hamiltonian' 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 'hamiltonian' transition operator that can
+be used more generally.
> import Numeric.AD (grad) > import Numeric.MCMC.Hamiltonian > > target ::
RealFloat a => [a] -> a > target [x0, x1] = negate ((x0 + 2 * x1 - 7) ^ 2 + (2
++++++ hasty-hamiltonian-1.1.5.tar.gz -> hasty-hamiltonian-1.3.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/hasty-hamiltonian-1.1.5/Numeric/MCMC/Hamiltonian.hs
new/hasty-hamiltonian-1.3.0/Numeric/MCMC/Hamiltonian.hs
--- old/hasty-hamiltonian-1.1.5/Numeric/MCMC/Hamiltonian.hs 2016-10-31
20:56:16.000000000 +0100
+++ new/hasty-hamiltonian-1.3.0/Numeric/MCMC/Hamiltonian.hs 2016-12-21
21:46:48.000000000 +0100
@@ -24,6 +24,7 @@
module Numeric.MCMC.Hamiltonian (
mcmc
+ , chain
, hamiltonian
-- * Re-exported
@@ -35,8 +36,11 @@
) where
import Control.Lens hiding (index)
+import Control.Monad (replicateM)
+import Control.Monad.Codensity (lowerCodensity)
+import Control.Monad.IO.Class (MonadIO, liftIO)
+import Control.Monad.Primitive (PrimState, PrimMonad)
import Control.Monad.Trans.State.Strict hiding (state)
-import Control.Monad.Primitive (PrimState, PrimMonad, RealWorld)
import qualified Data.Foldable as Foldable (sum)
import Data.Maybe (fromMaybe)
import Data.Sampling.Types
@@ -48,9 +52,10 @@
-- | Trace 'n' iterations of a Markov chain and stream them to stdout.
--
--- >>> withSystemRandom . asGenIO $ mcmc 3 1 [0, 0] target
+-- >>> withSystemRandom . asGenIO $ mcmc 10000 0.05 20 [0, 0] target
mcmc
- :: (Num (IxValue (t Double)), Show (t Double), Traversable t
+ :: ( MonadIO m, PrimMonad m
+ , Num (IxValue (t Double)), Show (t Double), Traversable t
, FunctorWithIndex (Index (t Double)) t, Ixed (t Double)
, IxValue (t Double) ~ Double)
=> Int
@@ -58,18 +63,47 @@
-> Int
-> t Double
-> Target (t Double)
- -> Gen RealWorld
- -> IO ()
+ -> Gen (PrimState m)
+ -> m ()
mcmc n step leaps chainPosition chainTarget gen = runEffect $
- chain step leaps Chain {..} gen
+ drive step leaps Chain {..} gen
>-> Pipes.take n
- >-> Pipes.mapM_ print
+ >-> Pipes.mapM_ (liftIO . print)
where
chainScore = lTarget chainTarget chainPosition
chainTunables = Nothing
--- A Markov chain driven by the Metropolis transition operator.
+-- | Trace 'n' iterations of a Markov chain and collect the results in a list.
+--
+-- >>> results <- withSystemRandom . asGenIO $ chain 1000 0.05 20 [0, 0] target
chain
+ :: (PrimMonad m, Traversable f
+ , FunctorWithIndex (Index (f Double)) f, Ixed (f Double)
+ , IxValue (f Double) ~ Double)
+ => Int
+ -> Double
+ -> Int
+ -> f Double
+ -> Target (f Double)
+ -> Gen (PrimState m)
+ -> m [Chain (f Double) b]
+chain n step leaps position target gen = runEffect $
+ drive step leaps origin gen
+ >-> collect n
+ where
+ origin = Chain {
+ chainScore = lTarget target position
+ , chainTunables = Nothing
+ , chainTarget = target
+ , chainPosition = position
+ }
+
+ collect :: Monad m => Int -> Consumer a m [a]
+ collect size = lowerCodensity $
+ replicateM size (lift Pipes.await)
+
+-- Drive a Markov chain.
+drive
:: (Num (IxValue (t Double)), Traversable t
, FunctorWithIndex (Index (t Double)) t, Ixed (t Double)
, PrimMonad m, IxValue (t Double) ~ Double)
@@ -77,8 +111,8 @@
-> Int
-> Chain (t Double) b
-> Gen (PrimState m)
- -> Producer (Chain (t Double) b) m ()
-chain step leaps = loop where
+ -> Producer (Chain (t Double) b) m c
+drive step leaps = loop where
loop state prng = do
next <- lift (MWC.sample (execStateT (hamiltonian step leaps) state) prng)
yield next
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/hasty-hamiltonian-1.1.5/hasty-hamiltonian.cabal
new/hasty-hamiltonian-1.3.0/hasty-hamiltonian.cabal
--- old/hasty-hamiltonian-1.1.5/hasty-hamiltonian.cabal 2016-12-04
10:04:50.000000000 +0100
+++ new/hasty-hamiltonian-1.3.0/hasty-hamiltonian.cabal 2016-12-21
21:49:39.000000000 +0100
@@ -1,5 +1,5 @@
name: hasty-hamiltonian
-version: 1.1.5
+version: 1.3.0
synopsis: Speedy traversal through parameter space.
homepage: http://github.com/jtobin/hasty-hamiltonian
license: MIT
@@ -8,7 +8,7 @@
maintainer: [email protected]
category: Numeric
build-type: Simple
-cabal-version: >=1.10
+cabal-version: >= 1.10
Description:
Gradient-based traversal through parameter space.
.
@@ -20,8 +20,9 @@
handy <https://hackage.haskell.org/package/ad ad> library for automatic
differentiation.
.
- Exports a 'mcmc' function that prints a trace to stdout, as well as a
- 'hamiltonian' 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 'hamiltonian' transition operator
+ that can be used more generally.
.
> import Numeric.AD (grad)
> import Numeric.MCMC.Hamiltonian
@@ -50,6 +51,7 @@
Numeric.MCMC.Hamiltonian
build-depends:
base >= 4 && < 6
+ , kan-extensions >= 5 && < 6
, mcmc-types >= 1.0.1
, mwc-probability >= 1.0.1
, lens >= 4 && < 5
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/hasty-hamiltonian-1.1.5/test/Booth.hs
new/hasty-hamiltonian-1.3.0/test/Booth.hs
--- old/hasty-hamiltonian-1.1.5/test/Booth.hs 2016-10-31 20:49:03.000000000
+0100
+++ new/hasty-hamiltonian-1.3.0/test/Booth.hs 2016-12-21 21:47:27.000000000
+0100
@@ -13,5 +13,7 @@
booth = Target target (Just gTarget)
main :: IO ()
-main = withSystemRandom . asGenIO $ mcmc 100 0.05 20 [0, 0] booth
+main = withSystemRandom . asGenIO $ \gen -> do
+ _ <- chain 100 0.05 20 [0, 0] booth gen
+ mcmc 100 0.05 20 [0, 0] booth gen