Hello community,

here is the log from the commit of package ghc-speedy-slice for 
openSUSE:Factory checked in at 2017-03-03 17:51:50
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/ghc-speedy-slice (Old)
 and      /work/SRC/openSUSE:Factory/.ghc-speedy-slice.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "ghc-speedy-slice"

Fri Mar  3 17:51:50 2017 rev:4 rq:461683 version:0.3.0

Changes:
--------
--- /work/SRC/openSUSE:Factory/ghc-speedy-slice/ghc-speedy-slice.changes        
2017-01-12 15:52:35.351016135 +0100
+++ /work/SRC/openSUSE:Factory/.ghc-speedy-slice.new/ghc-speedy-slice.changes   
2017-03-03 17:51:51.219097710 +0100
@@ -1,0 +2,5 @@
+Sun Feb 12 14:20:39 UTC 2017 - [email protected]
+
+- Update to version 0.3.0 with cabal2obs.
+
+-------------------------------------------------------------------

Old:
----
  speedy-slice-0.1.5.tar.gz

New:
----
  speedy-slice-0.3.0.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ ghc-speedy-slice.spec ++++++
--- /var/tmp/diff_new_pack.qQqujS/_old  2017-03-03 17:51:51.711028230 +0100
+++ /var/tmp/diff_new_pack.qQqujS/_new  2017-03-03 17:51:51.715027666 +0100
@@ -1,7 +1,7 @@
 #
 # spec file for package ghc-speedy-slice
 #
-# 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 speedy-slice
 %bcond_with tests
 Name:           ghc-%{pkg_name}
-Version:        0.1.5
+Version:        0.3.0
 Release:        0
 Summary:        Speedy slice sampling
 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 @@
 Additionally you can sample over anything that's an instance of both 'Num' and
 'Variate', which is useful in the case of discrete parameters.
 
-Exports a 'mcmc' function that prints a trace to stdout, as well as a 'slice'
-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 'slice' transition operator that can be
+used more generally.
 
 > import Numeric.MCMC.Slice > import Data.Sequence (Seq, index, fromList) > >
 bnn :: Seq Double -> Double > bnn xs = -0.5 * (x0 ^ 2 * x1 ^ 2 + x0 ^ 2 + x1 ^

++++++ speedy-slice-0.1.5.tar.gz -> speedy-slice-0.3.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/speedy-slice-0.1.5/Numeric/MCMC/Slice.hs 
new/speedy-slice-0.3.0/Numeric/MCMC/Slice.hs
--- old/speedy-slice-0.1.5/Numeric/MCMC/Slice.hs        2016-10-31 
20:45:32.000000000 +0100
+++ new/speedy-slice-0.3.0/Numeric/MCMC/Slice.hs        2016-12-21 
21:59:06.000000000 +0100
@@ -1,4 +1,4 @@
--- {-# OPTIONS_GHC -Wall #-}
+{-# OPTIONS_GHC -Wall #-}
 {-# LANGUAGE BangPatterns #-}
 {-# LANGUAGE RecordWildCards #-}
 {-# LANGUAGE FlexibleContexts #-}
@@ -28,6 +28,7 @@
 
 module Numeric.MCMC.Slice (
     mcmc
+  , chain
   , slice
 
   -- * Re-exported
@@ -37,8 +38,11 @@
   , MWC.asGenIO
   ) where
 
+import Control.Monad (replicateM)
+import Control.Monad.Codensity (lowerCodensity)
 import Control.Monad.Trans.State.Strict (put, get, execStateT)
-import Control.Monad.Primitive (PrimMonad, PrimState, RealWorld)
+import Control.Monad.Primitive (PrimMonad, PrimState)
+import Control.Monad.IO.Class (MonadIO, liftIO)
 import Control.Lens hiding (index)
 import Data.Maybe (fromMaybe)
 import Data.Sampling.Types
@@ -55,32 +59,62 @@
 -- -9.310661272172682e-2,0.2562387977415508
 -- -0.48500122500661846,0.46245400501919076
 mcmc
-  :: (Show (t a), FoldableWithIndex (Index (t a)) t, Ixed (t a),
+  :: (MonadIO m, PrimMonad m,
+     Show (t a), FoldableWithIndex (Index (t a)) t, Ixed (t a),
      Num (IxValue (t a)), Variate (IxValue (t a)))
   => Int
   -> IxValue (t a)
   -> t a
   -> (t a -> 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
     chainTarget   = Target target Nothing
 
--- A Markov chain driven by the slice transition operator.
+-- | Trace 'n' iterations of a Markov chain and collect them in a list.
+--
+-- >>> results <- withSystemRandom . asGenIO $ mcmc 3 1 [0, 0] rosenbrock
 chain
+  :: (PrimMonad m, FoldableWithIndex (Index (f a)) f, Ixed (f a)
+     , Variate (IxValue (f a)), Num (IxValue (f a)))
+  => Int
+  -> IxValue (f a)
+  -> f a
+  -> (f a -> Double)
+  -> Gen (PrimState m)
+  -> m [Chain (f a) 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)
+
+-- A Markov chain driven by the slice transition operator.
+drive
   :: (PrimMonad m, FoldableWithIndex (Index (t a)) t, Ixed (t a),
      Num (IxValue (t a)), Variate (IxValue (t a)))
   => IxValue (t a)
   -> Chain (t a) b
   -> Gen (PrimState m)
-  -> Producer (Chain (t a) b) m ()
-chain radial = loop where
+  -> Producer (Chain (t a) b) m c
+drive radial = loop where
   loop state prng = do
     next <- lift (MWC.sample (execStateT (slice radial) state) prng)
     yield next
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/speedy-slice-0.1.5/speedy-slice.cabal 
new/speedy-slice-0.3.0/speedy-slice.cabal
--- old/speedy-slice-0.1.5/speedy-slice.cabal   2016-12-04 09:57:44.000000000 
+0100
+++ new/speedy-slice-0.3.0/speedy-slice.cabal   2016-12-21 21:51:51.000000000 
+0100
@@ -1,5 +1,5 @@
 name:                speedy-slice
-version:             0.1.5
+version:             0.3.0
 synopsis:            Speedy slice sampling.
 homepage:            http://github.com/jtobin/speedy-slice
 license:             MIT
@@ -20,8 +20,9 @@
   Additionally you can sample over anything that's an instance of both 'Num' 
and
   'Variate', which is useful in the case of discrete parameters.
   .
-  Exports a 'mcmc' function that prints a trace to stdout, as well as a
-  'slice' 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 'slice' transition operator that can
+  be used more generally.
   .
   > import Numeric.MCMC.Slice
   > import Data.Sequence (Seq, index, fromList)
@@ -44,6 +45,7 @@
       Numeric.MCMC.Slice
   build-depends:
       base            >= 4 && < 6
+    , kan-extensions  >= 5 && < 6
     , lens            >= 4 && < 5
     , primitive       >= 0.6 && < 1.0
     , mcmc-types      >= 1.0.1
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/speedy-slice-0.1.5/test/BNN.hs 
new/speedy-slice-0.3.0/test/BNN.hs
--- old/speedy-slice-0.1.5/test/BNN.hs  2016-10-31 21:37:30.000000000 +0100
+++ new/speedy-slice-0.3.0/test/BNN.hs  2016-12-21 22:00:28.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/speedy-slice-0.1.5/test/Rosenbrock.hs 
new/speedy-slice-0.3.0/test/Rosenbrock.hs
--- old/speedy-slice-0.1.5/test/Rosenbrock.hs   2016-10-31 21:37:35.000000000 
+0100
+++ new/speedy-slice-0.3.0/test/Rosenbrock.hs   2016-12-21 22:00:32.000000000 
+0100
@@ -8,6 +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
 


Reply via email to