Hello community, here is the log from the commit of package ghc-declarative for openSUSE:Factory checked in at 2017-03-03 17:49:26 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ghc-declarative (Old) and /work/SRC/openSUSE:Factory/.ghc-declarative.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-declarative" Fri Mar 3 17:49:26 2017 rev:3 rq:461622 version:0.5.1 Changes: -------- --- /work/SRC/openSUSE:Factory/ghc-declarative/ghc-declarative.changes 2016-12-09 09:37:03.514393364 +0100 +++ /work/SRC/openSUSE:Factory/.ghc-declarative.new/ghc-declarative.changes 2017-03-03 17:49:27.267428655 +0100 @@ -1,0 +2,5 @@ +Sun Feb 12 14:13:06 UTC 2017 - [email protected] + +- Update to version 0.5.1 with cabal2obs. + +------------------------------------------------------------------- Old: ---- declarative-0.2.3.tar.gz New: ---- declarative-0.5.1.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ghc-declarative.spec ++++++ --- /var/tmp/diff_new_pack.ZlfUq1/_old 2017-03-03 17:49:27.795354096 +0100 +++ /var/tmp/diff_new_pack.ZlfUq1/_new 2017-03-03 17:49:27.799353531 +0100 @@ -1,7 +1,7 @@ # # spec file for package ghc-declarative # -# 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 declarative %bcond_with tests Name: ghc-%{pkg_name} -Version: 0.2.3 +Version: 0.5.1 Release: 0 Summary: DIY Markov Chains License: MIT @@ -28,6 +28,7 @@ Source0: https://hackage.haskell.org/package/%{pkg_name}-%{version}/%{pkg_name}-%{version}.tar.gz BuildRequires: ghc-Cabal-devel BuildRequires: ghc-hasty-hamiltonian-devel +BuildRequires: ghc-kan-extensions-devel BuildRequires: ghc-lens-devel BuildRequires: ghc-mcmc-types-devel BuildRequires: ghc-mighty-metropolis-devel ++++++ declarative-0.2.3.tar.gz -> declarative-0.5.1.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/declarative-0.2.3/declarative.cabal new/declarative-0.5.1/declarative.cabal --- old/declarative-0.2.3/declarative.cabal 2016-10-31 20:42:41.000000000 +0100 +++ new/declarative-0.5.1/declarative.cabal 2016-12-22 00:24:34.000000000 +0100 @@ -1,5 +1,5 @@ name: declarative -version: 0.2.3 +version: 0.5.1 synopsis: DIY Markov Chains. homepage: http://github.com/jtobin/declarative license: MIT @@ -58,18 +58,20 @@ default-language: Haskell2010 hs-source-dirs: lib exposed-modules: - Numeric.MCMC + Numeric.MCMC + , Numeric.MCMC.Anneal build-depends: base >= 4 && < 6 + , kan-extensions >= 5 && < 6 , mcmc-types >= 1.0.1 , mwc-probability >= 1.0.1 - , mighty-metropolis >= 1.0.1 + , mighty-metropolis >= 1.0.4 , lens >= 4 && < 5 - , primitive + , primitive >= 0.6 && < 1.0 , pipes >= 4 && < 5 - , hasty-hamiltonian >= 1.1.1 - , speedy-slice >= 0.1.2 - , transformers + , hasty-hamiltonian >= 1.1.5 + , speedy-slice >= 0.1.5 + , transformers >= 0.5 && < 1.0 Test-suite rosenbrock type: exitcode-stdio-1.0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/declarative-0.2.3/lib/Numeric/MCMC/Anneal.hs new/declarative-0.5.1/lib/Numeric/MCMC/Anneal.hs --- old/declarative-0.2.3/lib/Numeric/MCMC/Anneal.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/declarative-0.5.1/lib/Numeric/MCMC/Anneal.hs 2016-11-07 10:18:36.000000000 +0100 @@ -0,0 +1,80 @@ +{-# OPTIONS_GHC -fno-warn-type-defaults #-} +{-# LANGUAGE RecordWildCards #-} + +-- | +-- Module: Numeric.MCMC.Anneal +-- Copyright: (c) 2015 Jared Tobin +-- License: MIT +-- +-- Maintainer: Jared Tobin <[email protected]> +-- Stability: unstable +-- Portability: ghc +-- +-- Transition operators can easily be tweaked to operate over an /annealed/ +-- parameter space, which can be useful when sampling from bumpy landscapes +-- with isolated modes. +-- +-- This library exports a single 'anneal' function that allows one to run a +-- /declarative/-compatible transition operator over a space that has been +-- annealed to a specified temperature. +-- +-- > import Numeric.MCMC +-- > +-- > annealingTransition = do +-- > anneal 0.70 (metropolis 1) +-- > anneal 0.05 (metropolis 1) +-- > anneal 0.05 (metropolis 1) +-- > anneal 0.70 (metropolis 1) +-- > metropolis 1 +-- +-- These annealed operators can then just be used like any other: +-- +-- > himmelblau :: Target [Double] +-- > himmelblau = Target lHimmelblau Nothing where +-- > lHimmelblau :: [Double] -> Double +-- > lHimmelblau [x0, x1] = +-- > (-1) * ((x0 * x0 + x1 - 11) ^ 2 + (x0 + x1 * x1 - 7) ^ 2) +-- > +-- > main :: IO () +-- > main = withSystemRandom . asGenIO $ +-- > mcmc 10000 [0, 0] annealingTransition himmelblau + +module Numeric.MCMC.Anneal ( + anneal + ) where + +import Control.Monad.Trans.State.Strict (get, modify) +import Data.Sampling.Types (Transition, Chain(..), Target(..)) + +-- | An annealing transformer. +-- +-- When executed, the supplied transition operator will execute over the +-- parameter space annealed to the supplied inverse temperature. +-- +-- > let annealedTransition = anneal 0.30 (slice 0.5) +anneal + :: (Monad m, Functor f) + => Double + -> Transition m (Chain (f Double) b) + -> Transition m (Chain (f Double) b) +anneal invTemp baseTransition + | invTemp < 0 = error "anneal: invalid temperture" + | otherwise = do + Chain {..} <- get + let annealedTarget = annealer invTemp chainTarget + modify $ useTarget annealedTarget + baseTransition + modify $ useTarget chainTarget + +annealer :: Functor f => Double -> Target (f Double) -> Target (f Double) +annealer invTemp target = Target annealedL annealedG where + annealedL xs = invTemp * lTarget target xs + annealedG = + case glTarget target of + Nothing -> Nothing + Just g -> Just (fmap (* invTemp) . g) + +useTarget :: Target a -> Chain a b -> Chain a b +useTarget newTarget Chain {..} = + Chain newTarget (lTarget newTarget chainPosition) chainPosition chainTunables + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/declarative-0.2.3/lib/Numeric/MCMC.hs new/declarative-0.5.1/lib/Numeric/MCMC.hs --- old/declarative-0.2.3/lib/Numeric/MCMC.hs 2016-10-31 20:41:11.000000000 +0100 +++ new/declarative-0.5.1/lib/Numeric/MCMC.hs 2016-12-22 00:20:01.000000000 +0100 @@ -67,7 +67,9 @@ , sampleAllT , bernoulliT , frequency + , anneal , mcmc + , chain -- * Re-exported , module Data.Sampling.Types @@ -86,12 +88,16 @@ , RealWorld ) where +import Control.Monad (replicateM) +import Control.Monad.Codensity (lowerCodensity) +import Control.Monad.IO.Class (MonadIO, liftIO) import Control.Monad.Primitive (PrimMonad, PrimState, RealWorld) import Control.Monad.Trans.State.Strict (execStateT) import Data.Sampling.Types -import Numeric.MCMC.Metropolis hiding (mcmc) -import Numeric.MCMC.Hamiltonian hiding (mcmc) -import Numeric.MCMC.Slice hiding (mcmc) +import Numeric.MCMC.Anneal +import Numeric.MCMC.Metropolis (metropolis) +import Numeric.MCMC.Hamiltonian (hamiltonian) +import Numeric.MCMC.Slice (slice) import Pipes hiding (next) import qualified Pipes.Prelude as Pipes import System.Random.MWC.Probability (Gen) @@ -150,29 +156,51 @@ -- 1.4541485365128892e-2,-0.4859905564050404 -- 0.22487398491619448,-0.29769783186855125 mcmc - :: Show (t a) + :: (MonadIO m, PrimMonad m, Show (t a)) => Int -> t a - -> Transition IO (Chain (t a) b) + -> Transition m (Chain (t a) b) -> Target (t a) - -> Gen RealWorld - -> IO () + -> Gen (PrimState m) + -> m () mcmc n chainPosition transition chainTarget gen = runEffect $ - chain transition Chain {..} gen + drive transition Chain {..} gen >-> Pipes.take n - >-> Pipes.mapM_ print + >-> Pipes.mapM_ (liftIO . print) where chainScore = lTarget chainTarget chainPosition chainTunables = Nothing --- A Markov chain driven by an arbitrary transition operator. +-- | Trace 'n' iterations of a Markov chain and collect them in a list. +-- +-- >>> results <- withSystemRandom . asGenIO $ chain 3 [0, 0] (metropolis 0.5) rosenbrock chain + :: (MonadIO m, PrimMonad m) + => Int + -> t a + -> Transition m (Chain (t a) b) + -> Target (t a) + -> Gen (PrimState m) + -> m [Chain (t a) b] +chain n chainPosition transition chainTarget gen = runEffect $ + drive transition Chain {..} gen + >-> collect n + where + chainScore = lTarget chainTarget chainPosition + chainTunables = Nothing + + collect :: Monad m => Int -> Consumer a m [a] + collect size = lowerCodensity $ + replicateM size (lift Pipes.await) + +-- A Markov chain driven by an arbitrary transition operator. +drive :: PrimMonad m => Transition m b -> b -> Gen (PrimState m) -> Producer b m a -chain transition = loop where +drive transition = loop where loop state prng = do next <- lift (MWC.sample (execStateT transition state) prng) yield next diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/declarative-0.2.3/test/Rosenbrock.hs new/declarative-0.5.1/test/Rosenbrock.hs --- old/declarative-0.2.3/test/Rosenbrock.hs 2016-10-31 20:39:21.000000000 +0100 +++ new/declarative-0.5.1/test/Rosenbrock.hs 2016-12-21 22:07:22.000000000 +0100 @@ -17,5 +17,7 @@ (sampleT (slice 2.0) (slice 3.0)) main :: IO () -main = withSystemRandom . asGenIO $ mcmc 100 [0, 0] (slice 1.0) rosenbrock +main = withSystemRandom . asGenIO $ \gen -> do + _ <- chain 100 [0, 0] transition rosenbrock gen + mcmc 100 [0, 0] transition rosenbrock gen
