Hello community, here is the log from the commit of package ghc-flat-mcmc for openSUSE:Factory checked in at 2017-04-18 13:48:43 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ghc-flat-mcmc (Old) and /work/SRC/openSUSE:Factory/.ghc-flat-mcmc.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-flat-mcmc" Tue Apr 18 13:48:43 2017 rev:2 rq:479843 version:1.5.0 Changes: -------- --- /work/SRC/openSUSE:Factory/ghc-flat-mcmc/ghc-flat-mcmc.changes 2017-03-09 01:49:53.178018454 +0100 +++ /work/SRC/openSUSE:Factory/.ghc-flat-mcmc.new/ghc-flat-mcmc.changes 2017-04-18 13:48:44.464543938 +0200 @@ -1,0 +2,5 @@ +Sun Feb 12 14:20:07 UTC 2017 - psim...@suse.com + +- Update to version 1.5.0 with cabal2obs. + +------------------------------------------------------------------- Old: ---- flat-mcmc-1.0.1.tar.gz New: ---- flat-mcmc-1.5.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ghc-flat-mcmc.spec ++++++ --- /var/tmp/diff_new_pack.TpXxdv/_old 2017-04-18 13:48:45.120451103 +0200 +++ /var/tmp/diff_new_pack.TpXxdv/_new 2017-04-18 13:48:45.124450537 +0200 @@ -1,7 +1,7 @@ # # spec file for package ghc-flat-mcmc # -# 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,15 +19,15 @@ %global pkg_name flat-mcmc %bcond_with tests Name: ghc-%{pkg_name} -Version: 1.0.1 +Version: 1.5.0 Release: 0 Summary: Painless general-purpose sampling License: MIT -Group: System/Libraries +Group: Development/Languages/Other 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 -# Begin cabal-rpm deps: +BuildRequires: ghc-formatting-devel BuildRequires: ghc-mcmc-types-devel BuildRequires: ghc-monad-par-devel BuildRequires: ghc-monad-par-extras-devel @@ -35,10 +35,10 @@ BuildRequires: ghc-pipes-devel BuildRequires: ghc-primitive-devel BuildRequires: ghc-rpm-macros +BuildRequires: ghc-text-devel BuildRequires: ghc-transformers-devel BuildRequires: ghc-vector-devel BuildRoot: %{_tmppath}/%{name}-%{version}-build -# End cabal-rpm deps %description Flat-mcmc is a Haskell library for painless, efficient, general-purpose @@ -55,13 +55,13 @@ flat-mcmc exports an 'mcmc' function that prints a trace to stdout, as well as a 'flat' transition operator that can be used more generally. -> import Numeric.MCMC.Flat > import Data.Vector (Vector, toList, fromList) > > -rosenbrock :: Vector Double -> Double > rosenbrock xs = negate (5 *(x1 - x0 ^ -2) ^ 2 + 0.05 * (1 - x0) ^ 2) where > [x0, x1] = toList xs > > ensemble :: -Ensemble > ensemble = fromList [ > fromList [negate 1.0, negate 1.0] > , -fromList [negate 1.0, 1.0] > , fromList [1.0, negate 1.0] > , fromList [1.0, -1.0] > ] > > main :: IO () > main = withSystemRandom . asGenIO $ mcmc 12500 -ensemble rosenbrock. +> import Numeric.MCMC.Flat > import qualified Data.Vector.Unboxed as U +(unsafeIndex) > > rosenbrock :: Particle -> Double > rosenbrock xs = negate (5 +* (x1 - x0 ^ 2) ^ 2 + 0.05 * (1 - x0) ^ 2) where > x0 = U.unsafeIndex xs 0 > x1 += U.unsafeIndex xs 1 > > origin :: Ensemble > origin = ensemble [ > particle +[negate 1.0, negate 1.0] > , particle [negate 1.0, 1.0] > , particle [1.0, +negate 1.0] > , particle [1.0, 1.0] > ] > > main :: IO () > main = +withSystemRandom . asGenIO $ mcmc 12500 origin rosenbrock. %package devel Summary: Haskell %{pkg_name} library development files @@ -77,20 +77,14 @@ %prep %setup -q -n %{pkg_name}-%{version} - %build %ghc_lib_build - %install %ghc_lib_install - %check -%if %{with tests} -%{cabal} test -%endif - +%cabal_test %post devel %ghc_pkg_recache ++++++ flat-mcmc-1.0.1.tar.gz -> flat-mcmc-1.5.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/flat-mcmc-1.0.1/flat-mcmc.cabal new/flat-mcmc-1.5.0/flat-mcmc.cabal --- old/flat-mcmc-1.0.1/flat-mcmc.cabal 2016-04-06 15:41:50.000000000 +0200 +++ new/flat-mcmc-1.5.0/flat-mcmc.cabal 2016-12-19 19:40:05.000000000 +0100 @@ -1,14 +1,14 @@ name: flat-mcmc -version: 1.0.1 +version: 1.5.0 synopsis: Painless general-purpose sampling. -homepage: http://jtobin.github.com/flat-mcmc +homepage: https://github.com/jtobin/flat-mcmc license: MIT license-file: LICENSE author: Jared Tobin maintainer: ja...@jtobin.ca category: Math build-type: Simple -cabal-version: >=1.10 +cabal-version: >= 1.18 description: flat-mcmc is a Haskell library for painless, efficient, general-purpose sampling from continuous distributions. @@ -25,22 +25,23 @@ as a 'flat' transition operator that can be used more generally. . > import Numeric.MCMC.Flat - > import Data.Vector (Vector, toList, fromList) + > import qualified Data.Vector.Unboxed as U (unsafeIndex) > - > rosenbrock :: Vector Double -> Double - > rosenbrock xs = negate (5 *(x1 - x0 ^ 2) ^ 2 + 0.05 * (1 - x0) ^ 2) where - > [x0, x1] = toList xs + > rosenbrock :: Particle -> Double + > rosenbrock xs = negate (5 * (x1 - x0 ^ 2) ^ 2 + 0.05 * (1 - x0) ^ 2) where + > x0 = U.unsafeIndex xs 0 + > x1 = U.unsafeIndex xs 1 > - > ensemble :: Ensemble - > ensemble = fromList [ - > fromList [negate 1.0, negate 1.0] - > , fromList [negate 1.0, 1.0] - > , fromList [1.0, negate 1.0] - > , fromList [1.0, 1.0] + > origin :: Ensemble + > origin = ensemble [ + > particle [negate 1.0, negate 1.0] + > , particle [negate 1.0, 1.0] + > , particle [1.0, negate 1.0] + > , particle [1.0, 1.0] > ] > > main :: IO () - > main = withSystemRandom . asGenIO $ mcmc 12500 ensemble rosenbrock + > main = withSystemRandom . asGenIO $ mcmc 12500 origin rosenbrock Source-repository head Type: git @@ -48,19 +49,28 @@ library default-language: Haskell2010 - ghc-options: -Wall hs-source-dirs: lib - exposed-modules: Numeric.MCMC.Flat + ghc-options: + -Wall + + exposed-modules: + Numeric.MCMC.Flat + + other-modules: + Data.Vector.Extended + build-depends: - base < 5 + base > 4 && < 6 + , formatting >= 6 && < 7 , mcmc-types >= 1.0.1 && < 2 - , monad-par - , monad-par-extras + , monad-par >= 0.3.4.7 && < 1 + , monad-par-extras >= 0.3.3 && < 1 , mwc-probability >= 1.0.1 && < 2 - , pipes >= 4 && < 5 - , primitive - , transformers - , vector + , pipes >= 4 && < 5 + , primitive >= 0.6 && < 1 + , text >= 1.2 && < 2 + , transformers >= 0.2 && < 0.6 + , vector >= 0.10 && < 1 Test-suite rosenbrock type: exitcode-stdio-1.0 @@ -70,7 +80,7 @@ ghc-options: -rtsopts -threaded build-depends: - base < 5 + base , flat-mcmc , vector @@ -82,7 +92,7 @@ ghc-options: -rtsopts -threaded build-depends: - base < 5 + base , flat-mcmc , vector diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/flat-mcmc-1.0.1/lib/Data/Vector/Extended.hs new/flat-mcmc-1.5.0/lib/Data/Vector/Extended.hs --- old/flat-mcmc-1.0.1/lib/Data/Vector/Extended.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/flat-mcmc-1.5.0/lib/Data/Vector/Extended.hs 2016-11-30 21:41:59.000000000 +0100 @@ -0,0 +1,29 @@ +-- | +-- Module: Data.Vector.Extended +-- Copyright: (c) 2016 Jared Tobin +-- License: MIT +-- +-- Maintainer: Jared Tobin <ja...@jtobin.ca> +-- Stability: unstable +-- Portability: ghc + +module Data.Vector.Extended ( + ensemble + , particle + ) where + +import qualified Data.Vector as V (fromList, Vector) +import qualified Data.Vector.Unboxed as U (fromList, Vector) + +-- | A type-specialized alias for Data.Vector.fromList. +-- +-- Use this to create ensembles from lists of particles. +ensemble :: [U.Vector Double] -> V.Vector (U.Vector Double) +ensemble = V.fromList + +-- | A type-specialized alias for Data.Vector.Unboxed.fromList +-- +-- Use this to create particles from lists of doubles. +particle :: [Double] -> U.Vector Double +particle = U.fromList + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/flat-mcmc-1.0.1/lib/Numeric/MCMC/Flat.hs new/flat-mcmc-1.5.0/lib/Numeric/MCMC/Flat.hs --- old/flat-mcmc-1.0.1/lib/Numeric/MCMC/Flat.hs 2016-04-06 12:00:31.000000000 +0200 +++ new/flat-mcmc-1.5.0/lib/Numeric/MCMC/Flat.hs 2016-12-19 19:40:23.000000000 +0100 @@ -1,4 +1,6 @@ {-# OPTIONS_GHC -fno-warn-type-defaults #-} +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} -- | @@ -34,18 +36,28 @@ , MWC.createSystemRandom , MWC.withSystemRandom , MWC.asGenIO + + , VE.ensemble + , VE.particle ) where import Control.Monad (replicateM) +import Control.Monad.IO.Class (MonadIO, liftIO) import Control.Monad.Par (NFData) -import Control.Monad.Par.Scheds.Direct hiding (put, get) import Control.Monad.Par.Combinator (parMap) -import Control.Monad.Primitive (PrimMonad, PrimState, RealWorld) +import Control.Monad.Par.Scheds.Sparks hiding (get) +import Control.Monad.Primitive (PrimMonad, PrimState) import Control.Monad.Trans.State.Strict (get, put, execStateT) +import Data.Monoid import Data.Sampling.Types as Sampling.Types hiding (Chain(..)) +import qualified Data.Text as T +import qualified Data.Text.IO as T (putStrLn) import Data.Vector (Vector) import qualified Data.Vector as V +import qualified Data.Vector.Extended as VE (ensemble, particle) import qualified Data.Vector.Unboxed as U +import Formatting ((%)) +import qualified Formatting as F import Pipes (Producer, lift, yield, runEffect, (>->)) import qualified Pipes.Prelude as Pipes import System.Random.MWC.Probability as MWC @@ -55,39 +67,68 @@ , chainPosition :: !Ensemble } -instance Show Chain where - show Chain {..} = - init - . filter (`notElem` "[]") - . unlines - . V.toList - . V.map show - $ chainPosition +-- | Render a Chain as a text value. +render :: Chain -> T.Text +render Chain {..} = renderEnsemble chainPosition +{-# INLINE render #-} + +renderParticle :: Particle -> T.Text +renderParticle = + T.drop 1 + . U.foldl' glue mempty + where + glue = F.sformat (F.stext % "," % F.float) +{-# INLINE renderParticle #-} -type Particle = Vector Double +renderEnsemble :: Ensemble -> T.Text +renderEnsemble = + T.drop 1 + . V.foldl' glue mempty + where + glue a b = a <> "\n" <> renderParticle b +{-# INLINE renderEnsemble #-} + +-- | A particle is an n-dimensional point in Euclidean space. +-- +-- You can create a particle by using the 'particle' helper function, or just +-- use Data.Vector.Unboxed.fromList. +type Particle = U.Vector Double +-- | An ensemble is a collection of particles. +-- +-- The Markov chain we're interested in will run over the space of ensembles, +-- so you'll want to build an ensemble out of a reasonable number of +-- particles to kick off the chain. +-- +-- You can create an ensemble by using the 'ensemble' helper function, or just +-- use Data.Vector.fromList. type Ensemble = Vector Particle symmetric :: PrimMonad m => Prob m Double symmetric = fmap transform uniform where transform z = 0.5 * (z + 1) ^ (2 :: Int) +{-# INLINE symmetric #-} stretch :: Particle -> Particle -> Double -> Particle -stretch p0 p1 z = V.zipWith (+) (V.map (* z) p0) (V.map (* (1 - z)) p1) +stretch p0 p1 z = U.zipWith str p0 p1 where + str x y = z * x + (1 - z) * y +{-# INLINE stretch #-} acceptProb :: Target Particle -> Particle -> Particle -> Double -> Double acceptProb target particle proposal z = lTarget target proposal - lTarget target particle - + log z * (fromIntegral (V.length particle) - 1) + + log z * (fromIntegral (U.length particle) - 1) +{-# INLINE acceptProb #-} move :: Target Particle -> Particle -> Particle -> Double -> Double -> Particle -move target p0 p1 z zc = - let proposal = stretch p0 p1 z +move target !p0 p1 z zc = + let !proposal = stretch p0 p1 z pAccept = acceptProb target p0 proposal z in if zc <= min 1 (exp pAccept) then proposal else p0 +{-# INLINE move #-} execute :: PrimMonad m @@ -99,20 +140,19 @@ execute target e0 e1 n = do zs <- replicateM n symmetric zcs <- replicateM n uniform - vjs <- replicateM n (uniformR (1, n)) + js <- U.replicateM n (uniformR (1, n)) - let granularity = truncate (fromIntegral n / 2) + let granularity = n `div` 2 - js = U.fromList vjs w0 k = e0 `V.unsafeIndex` pred k w1 k ks = e1 `V.unsafeIndex` pred (ks `U.unsafeIndex` pred k) - worker (k, z, zc) = move target (w0 k) (w1 k js) z zc - result = runPar $ + !result = runPar $ parMapChunk granularity worker (zip3 [1..n] zs zcs) - return $ V.fromList result + return $! V.fromList result +{-# INLINE execute #-} -- | The 'flat' transition operator for driving a Markov chain over a space -- of ensembles. @@ -123,12 +163,13 @@ Chain {..} <- get let size = V.length chainPosition n = truncate (fromIntegral size / 2) - e0 = V.slice 0 n chainPosition - e1 = V.slice n n chainPosition + e0 = V.unsafeSlice 0 n chainPosition + e1 = V.unsafeSlice n n chainPosition result0 <- lift (execute chainTarget e0 e1 n) result1 <- lift (execute chainTarget e1 result0 n) - let ensemble = V.concat [result0, result1] - put (Chain chainTarget ensemble) + let !ensemble = V.concat [result0, result1] + put $! (Chain chainTarget ensemble) +{-# INLINE flat #-} chain :: PrimMonad m => Chain -> Gen (PrimState m) -> Producer Chain m () chain = loop where @@ -136,6 +177,7 @@ next <- lift (MWC.sample (execStateT flat state) prng) yield next loop next prng +{-# INLINE chain #-} -- | Trace 'n' iterations of a Markov chain and stream them to stdout. -- @@ -143,20 +185,20 @@ -- you'll need to provide an ensemble of particles for the start location. -- -- >>> import Numeric.MCMC.Flat --- >>> import Data.Vector (Vector, toList, fromList) +-- >>> import Data.Vector.Unboxed (toList) -- >>> :{ -- >>> let rosenbrock xs = negate (5 *(x1 - x0 ^ 2) ^ 2 + 0.05 * (1 - x0) ^ 2) -- where [x0, x1] = toList xs -- >>> :} -- >>> :{ --- >>> let ensemble = fromList [ --- >>> fromList [negate 1.0, negate 1.0] --- >>> , fromList [negate 1.0, 1.0] --- >>> , fromList [1.0, negate 1.0] --- >>> , fromList [1.0, 1.0] +-- >>> let origin = ensemble [ +-- >>> particle [negate 1.0, negate 1.0] +-- >>> , particle [negate 1.0, 1.0] +-- >>> , particle [1.0, negate 1.0] +-- >>> , particle [1.0, 1.0] -- >>> ] -- >>> :} --- >>> withSystemRandom . asGenIO $ mcmc 2 ensemble rosenbrock +-- >>> withSystemRandom . asGenIO $ mcmc 2 origin rosenbrock -- -1.0,-1.0 -- -1.0,1.0 -- 1.0,-1.0 @@ -165,13 +207,20 @@ -- -1.1655594505975082,1.1655594505975082 -- 0.5466534497342876,-0.9615123448709006 -- 0.7049046915549257,0.7049046915549257 -mcmc :: Int -> Ensemble -> (Particle -> Double) -> Gen RealWorld -> IO () +mcmc + :: (MonadIO m, PrimMonad m) + => Int + -> Ensemble + -> (Particle -> Double) + -> Gen (PrimState m) + -> m () mcmc n chainPosition target gen = runEffect $ chain Chain {..} gen >-> Pipes.take n - >-> Pipes.mapM_ print + >-> Pipes.mapM_ (liftIO . T.putStrLn . render) where chainTarget = Target target Nothing +{-# INLINE mcmc #-} -- A parallel map with the specified granularity. parMapChunk :: NFData b => Int -> (a -> b) -> [a] -> Par [b] @@ -180,4 +229,5 @@ chunk m ys = let (as, bs) = splitAt m ys in as : chunk m bs +{-# INLINE parMapChunk #-} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/flat-mcmc-1.0.1/test/BNN.hs new/flat-mcmc-1.5.0/test/BNN.hs --- old/flat-mcmc-1.0.1/test/BNN.hs 2016-04-06 15:23:32.000000000 +0200 +++ new/flat-mcmc-1.5.0/test/BNN.hs 2016-11-30 22:47:44.000000000 +0100 @@ -3,20 +3,21 @@ module Main where import Numeric.MCMC.Flat -import Data.Vector (Vector, toList, fromList) +import qualified Data.Vector.Unboxed as U (unsafeIndex) -bnn :: Vector Double -> Double +bnn :: Particle -> Double bnn xs = -0.5 * (x0 ^ 2 * x1 ^ 2 + x0 ^ 2 + x1 ^ 2 - 8 * x0 - 8 * x1) where - [x0, x1] = toList xs + x0 = U.unsafeIndex xs 0 + x1 = U.unsafeIndex xs 1 -ensemble :: Ensemble -ensemble = fromList [ - fromList [negate 1.0, negate 1.0] - , fromList [negate 1.0, 1.0] - , fromList [1.0, negate 1.0] - , fromList [1.0, 1.0] +origin :: Ensemble +origin = ensemble [ + particle [negate 1.0, negate 1.0] + , particle [negate 1.0, 1.0] + , particle [1.0, negate 1.0] + , particle [1.0, 1.0] ] main :: IO () -main = withSystemRandom . asGenIO $ mcmc 100 ensemble bnn +main = withSystemRandom . asGenIO $ mcmc 100 origin bnn diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/flat-mcmc-1.0.1/test/Rosenbrock.hs new/flat-mcmc-1.5.0/test/Rosenbrock.hs --- old/flat-mcmc-1.0.1/test/Rosenbrock.hs 2016-04-03 15:57:30.000000000 +0200 +++ new/flat-mcmc-1.5.0/test/Rosenbrock.hs 2016-11-30 22:47:55.000000000 +0100 @@ -3,20 +3,21 @@ module Main where import Numeric.MCMC.Flat -import Data.Vector (Vector, toList, fromList) +import qualified Data.Vector.Unboxed as U (unsafeIndex) -rosenbrock :: Vector Double -> Double +rosenbrock :: Particle -> Double rosenbrock xs = negate (5 *(x1 - x0 ^ 2) ^ 2 + 0.05 * (1 - x0) ^ 2) where - [x0, x1] = toList xs + x0 = U.unsafeIndex xs 0 + x1 = U.unsafeIndex xs 1 -ensemble :: Ensemble -ensemble = fromList [ - fromList [negate 1.0, negate 1.0] - , fromList [negate 1.0, 1.0] - , fromList [1.0, negate 1.0] - , fromList [1.0, 1.0] +origin :: Ensemble +origin = ensemble [ + particle [negate 1.0, negate 1.0] + , particle [negate 1.0, 1.0] + , particle [1.0, negate 1.0] + , particle [1.0, 1.0] ] main :: IO () -main = withSystemRandom . asGenIO $ mcmc 100 ensemble rosenbrock +main = withSystemRandom . asGenIO $ mcmc 100 origin rosenbrock