markov-realization 0.3.2 → 0.3.3
raw patch · 4 files changed
+16/−17 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Markov.Example: expectedLoss :: (Fractional a, Ord a, Markov ((,) (Product a)) FillBin) => [Product a :* FillBin] -> a
+ Markov.Example: expectedLoss :: (Fractional a, Markov ((,) (Product a)) FillBin) => [Product a :* FillBin] -> a
Files
- README.md +1/−3
- markov-realization.cabal +3/−1
- src/Markov.hs +2/−2
- src/Markov/Example.hs +10/−11
README.md view
@@ -29,9 +29,7 @@ ```haskell newtype Extinction = Extinction Int- deriving Generic- deriving newtype (Eq, Num, Show)- deriving anyclass Grouping+ deriving newtype (Eq, Num, Ord, Show) ``` Combining identical states should not change the state,
markov-realization.cabal view
@@ -7,7 +7,7 @@ -- hash: b164fe328e9edef0858d48e61b56997280bd4bb2ea6ffe923afb24084a14efe6 name: markov-realization-version: 0.3.2+version: 0.3.3 description: Please see the README on GitHub at <https://github.com/alexloomis/markov#markov-tutorial> homepage: https://github.com/alexloomis/markov bug-reports: https://github.com/alexloomis/markov/issues@@ -37,6 +37,7 @@ Paths_markov_realization hs-source-dirs: src+ ghc-options: -Wall -Wcompat -Wincomplete-uni-patterns -Wincomplete-record-updates -Wredundant-constraints build-depends: base >=4.7 && <5 , comonad@@ -51,6 +52,7 @@ hs-source-dirs: test ghc-options: -threaded -rtsopts -with-rtsopts=-N+ -Wall -Wcompat -Wincomplete-uni-patterns -Wincomplete-record-updates -Wredundant-constraints build-depends: base >=4.7 && <5 , HTF
src/Markov.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}@@ -38,7 +37,7 @@ import Control.Comonad (Comonad, extract) -import qualified Data.List as DL+import qualified Data.List as DL import qualified Data.List.NonEmpty as NE ---------------------------------------------------------------@@ -155,3 +154,4 @@ instance Num a => Semigroup (Product a) where x <> y = x * y instance Num a => Monoid (Product a) where mempty = 1+
src/Markov/Example.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-}@@ -29,8 +28,8 @@ , expectedLoss ) where -import Markov-import Markov.Extra+import Markov+import Markov.Extra import qualified Markov.Generic as MG ---------------------------------------------------------------@@ -255,7 +254,7 @@ instance Show FillBin where show (Ext g b s) = show g ++ " " ++ show b ++ " " ++ show s- show (End g) = show g+ show (End g) = show g instance Combine FillBin where combine = const @@ -329,27 +328,27 @@ -- @take i s ++ f (drop i s)@. iApply :: Trans -> Index -> Trans iApply f idx x = case (idx,x) of- (1, y) -> f y+ (1, y) -> f y (i, Ext g b s) -> Ext g b $ iApply f (i-1) s- _ -> error "Pattern not matched in iApply"+ _ -> error "Pattern not matched in iApply" -- |Add an item to the ith bin. addItem :: Index -> Trans addItem = iApply h where h (Ext g (o,f) s) = Ext g (o-1,f+1) s- h _ = error "pattern not matched in h in addItem"+ h _ = error "pattern not matched in h in addItem" -- |Expand the ith bin to the left by j. -- The Markov chain will use @addItem i . growLeft j i@. growLeft :: Int -> Index -> Trans growLeft j = iApply h where h (Ext g (o,f) s) = Ext (g-j) (o+j,f) s- h _ = error "pattern not matched in h in growLeft"+ h _ = error "pattern not matched in h in growLeft" growRight :: Int -> Index -> Trans growRight j = iApply h where h (Ext g (o,f) s) = Ext g (o+j,f) (shrink s)- h _ = error "pattern not matched in h in growRight"+ h _ = error "pattern not matched in h in growRight" shrink = \case End g -> End (g-j) Ext g b t -> Ext (g-j) b t@@ -364,7 +363,7 @@ | slots x == 0 = 1 | otherwise = 0 -divInt :: (Integral a, Integral b, Fractional c) => a -> b -> c+divInt :: Fractional a => Int -> Int -> a divInt x y = fromIntegral x / fromIntegral y -- |The probability that the ith bin gains an item.@@ -405,7 +404,7 @@ -- -- >>> expectedLoss [pure $ initial [1,0,3] :: (Product Double, FillBin)] -- 2.0-expectedLoss :: (Fractional a, Ord a, Markov ((,) (Product a)) FillBin) +expectedLoss :: (Fractional a, Markov ((,) (Product a)) FillBin) => [Product a :* FillBin] -> a expectedLoss xs = sum . map probLoss $ chain xs !! idx where idx = slots . snd . head $ xs