packages feed

mwc-probability-transition 0.1.0.0 → 0.2.0.0

raw patch · 3 files changed

+34/−13 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- System.Random.MWC.Probability.Transition: Alert :: Severity
- System.Random.MWC.Probability.Transition: Critical :: Severity
- System.Random.MWC.Probability.Transition: Debug :: Severity
- System.Random.MWC.Probability.Transition: Emergency :: Severity
- System.Random.MWC.Probability.Transition: Error :: Severity
- System.Random.MWC.Probability.Transition: Informational :: Severity
- System.Random.MWC.Probability.Transition: Notice :: Severity
- System.Random.MWC.Probability.Transition: Warning :: Severity
- System.Random.MWC.Probability.Transition: WithSeverity :: Severity -> a -> WithSeverity a
- System.Random.MWC.Probability.Transition: [discardSeverity] :: WithSeverity a -> a
- System.Random.MWC.Probability.Transition: [msgSeverity] :: WithSeverity a -> Severity
- System.Random.MWC.Probability.Transition: data Severity :: *
- System.Random.MWC.Probability.Transition: data WithSeverity a :: * -> *
- System.Random.MWC.Probability.Transition: type Handler (m :: * -> *) message = message -> m ()
+ System.Random.MWC.Probability.Transition: instance GHC.Show.Show (System.Random.MWC.Probability.Transition.Transition msg s m a)
- System.Random.MWC.Probability.Transition: runTransition :: Monad m => Handler m message -> Transition message s m a -> Int -> s -> Gen (PrimState m) -> m [(a, s)]
+ System.Random.MWC.Probability.Transition: runTransition :: Monad m => Handler m message -> Transition message s m a -> Int -> s -> Gen (PrimState m) -> m ([a], s)

Files

mwc-probability-transition.cabal view
@@ -1,5 +1,5 @@ name:                mwc-probability-transition-version:             0.1.0.0+version:             0.2.0.0 synopsis:            A Markov stochastic transition operator with logging description:             .@@ -31,8 +31,6 @@                      , primitive                      , transformers -- test-suite spec   default-language:    Haskell2010   ghc-options:         -Wall@@ -40,6 +38,7 @@   hs-source-dirs:      test   main-is:             LibSpec.hs   build-depends:       base+                     , mwc-probability                      , mwc-probability-transition                      , hspec                      , QuickCheck
src/System/Random/MWC/Probability/Transition.hs view
@@ -1,5 +1,6 @@ {-# language OverloadedStrings #-} {-# language DeriveFunctor, GeneralizedNewtypeDeriving #-}+{-# language FlexibleContexts #-} module System.Random.MWC.Probability.Transition (   -- * Transition     Transition@@ -7,10 +8,10 @@   , runTransition   -- ** Helper functions   , withSeverity-  -- * Re-exported from `logging-effect`-  , Handler-  , WithSeverity(..), Severity(..)-  -- , withFDHandler, defaultBatchingOptions+  -- -- * Re-exported from `logging-effect`+  -- , Handler+  -- , WithSeverity(..), Severity(..)+  -- -- , withFDHandler, defaultBatchingOptions   ) where  import Control.Monad@@ -33,6 +34,9 @@   Gen (PrimState m) -> StateT s (LoggingT message m) a   ) deriving (Functor) +instance Show (Transition msg s m a) where+  show _ = "<Transition>"+ -- | Construct a 'Transition' from sampling, state transformation and logging functions. -- -- NB: The three function arguments are used in the order in which they appear here:@@ -45,7 +49,7 @@ mkTransition :: Monad m =>         (s -> Prob m t)     -- ^ Random generation      -> (s -> t -> (a, s))  -- ^ (Output, Next state)-     -> (a -> s -> message) -- ^ Log message generation+     -> (a -> s -> message) -- ^ Log message construction      -> Transition message s m a mkTransition fm fs flog = Transition $ \gen -> do   s <- S.get@@ -62,12 +66,14 @@       -> Int                      -- ^ Number of iterations        -> s                        -- ^ Initial state       -> Gen (PrimState m)        -- ^ PRNG-      -> m [(a, s)]+      -> m ([a], s)               -- ^ (Outputs, Final state) runTransition logf (Transition fm) n s0 g =-  runLoggingT (replicateM n (runStateT (fm g) s0)) logf+  runLoggingT (runStateT (replicateM n (fm g)) s0) logf   ++-- * Helpers    bracketsUpp :: Show a => a -> String bracketsUpp p = unwords ["[", map toUpper (show p), "]"]
test/LibSpec.hs view
@@ -3,14 +3,30 @@ import Test.Hspec import Test.Hspec.QuickCheck +import System.Random.MWC.Probability+import System.Random.MWC.Probability.Transition + main :: IO () main = hspec spec  spec :: Spec spec =-  describe "Lib" $ do-    it "works" $ do-      True `shouldBe` True+  describe "System.Random.MWC.Probability.Transition" $ do+    it "computes the final state of a sequence of deterministic transitions" $ do+      (_, z) <- runT01+      z `shouldBe` 5     -- prop "ourAdd is commutative" $ \x y ->     --   ourAdd x y `shouldBe` ourAdd y x+++runT01 :: IO ([Double], Double)+runT01 = create >>= runTransition (putStrLn . withSeverity id) t01 5 0++t01 :: Monad m => Transition (WithSeverity String) Double m Double+t01 = mkTransition modelf statef logf where+  modelf _ = pure (1 :: Double)+  statef s t = (t, s + 1)+  logf _ s = WithSeverity Informational (show s)++