probability 0.2.1 → 0.2.2
raw patch · 7 files changed
+64/−23 lines, 7 filesdep +transformersdep −mtldep ~containersdep ~randomPVP ok
version bump matches the API change (PVP)
Dependencies added: transformers
Dependencies removed: mtl
Dependency ranges changed: containers, random
API changes (from Hackage documentation)
+ Numeric.Probability.Example.Profession: categories :: Dist Int
+ Numeric.Probability.Example.Profession: correctAnswers :: Dist Int
+ Numeric.Probability.Example.Profession: type Dist a = T Probability a
+ Numeric.Probability.Example.Profession: type Probability = Double
Files
- ToDo +3/−0
- probability.cabal +16/−6
- src/Numeric/Probability/Example/Collection.hs +2/−2
- src/Numeric/Probability/Example/Profession.hs +32/−0
- src/Numeric/Probability/Monad.hs +7/−7
- src/Numeric/Probability/Random.hs +2/−2
- src/Numeric/Probability/Show.hs +2/−6
ToDo view
@@ -1,3 +1,6 @@+the library could benefit from Monad transformers like WriterT and Product, see+ http://www.randomhacks.net/articles/2007/02/21/refactoring-probability-distributions+ Examples: Election and prognoses
probability.cabal view
@@ -1,10 +1,10 @@ Name: probability-Version: 0.2.1+Version: 0.2.2 License: BSD3 License-File: COPYRIGHT Author: Martin Erwig <erwig@eecs.oregonstate.edu>, Steve Kollmansberger Maintainer: Henning Thielemann <haskell@henning-thielemann.de>-Homepage: http://darcs.haskell.org/probability+Homepage: http://haskell.org/haskellwiki/Probabilistic_Functional_Programming Category: Math, Monads, Graphics Synopsis: Probabilistic Functional Programming Description:@@ -14,20 +14,29 @@ but extends the List monad by a measure of probability. Small interface to R plotting. Tested-With: GHC==6.4.1, GHC==6.8.2-Cabal-Version: >=1.2+Cabal-Version: >=1.6 Build-Type: Simple- Data-Files: README ToDo +Source-Repository head+ type: darcs+ location: http://darcs.haskell.org/probability/++Source-Repository this+ type: darcs+ location: http://darcs.haskell.org/probability/+ tag: 0.2.2++ Flag splitBase description: Choose the new smaller, split-up base package. Library- Build-Depends: mtl+ Build-Depends: transformers >=0.0.1 && <0.2 If flag(splitBase)- Build-Depends: base >= 2, random, containers+ Build-Depends: base >= 2, random >=1.0 && <2, containers >=0.1 && <1 Else Build-Depends: base >= 1.0 && < 2 @@ -55,6 +64,7 @@ Numeric.Probability.Example.MontyHall Numeric.Probability.Example.NBoys Numeric.Probability.Example.Predator+ Numeric.Probability.Example.Profession Numeric.Probability.Example.Queuing Numeric.Probability.Example.TreeGrowth Other-Modules:
src/Numeric/Probability/Example/Collection.hs view
@@ -8,8 +8,8 @@ import Numeric.Probability.Percentage (Dist) import Numeric.Probability.Monad (doWhile, )-import Control.Monad.State- (StateT(StateT, runStateT), evalStateT, liftM2, replicateM)+import Control.Monad.Trans.State (StateT(StateT, runStateT), evalStateT, )+import Control.Monad (liftM2, replicateM, ) import qualified Data.List as List import System.Random (Random)
+ src/Numeric/Probability/Example/Profession.hs view
@@ -0,0 +1,32 @@+{- |+The newspaper "Sueddeutsche" asked their readers+what professions 16 persons have,+by only showing the photographies of them and three choices.++Their statistics was:+22% readers had 0 to 5 correct answers (category 0)+75% readers had 6 to 11 correct answers (category 1)+ 3% readers had 12 to 16 correct answers (category 2)++Can this statistics be explained with random guessing,+or is there some information in the photographies+that the readers could utilize?++I got 6 correct answers.+-}++module Numeric.Probability.Example.Profession where++import qualified Numeric.Probability.Distribution as Dist+++-- type Probability = Rational+type Probability = Double+type Dist a = Dist.T Probability a++correctAnswers :: Dist Int+correctAnswers = sum $ replicate 16 $ Dist.fromFreqs [(0,2), (1,1)]++categories :: Dist Int+categories =+ Dist.map (\n -> if n<=5 then 0 else if n<=11 then 1 else 2) correctAnswers
src/Numeric/Probability/Monad.hs view
@@ -20,9 +20,9 @@ -- | like 'iterate' but returns all intermediate values walk :: (Monad m) => Int -> (a -> m a) -> (a -> m [a]) walk n f =- let recurse 0 _ = return []- recurse m x = liftM (x:) (recurse (pred m) =<< f x)- in recurse n+ let recourse 0 _ = return []+ recourse m x = liftM (x:) (recourse (pred m) =<< f x)+ in recourse n {- |@@ -31,8 +31,8 @@ -} doWhile :: Monad m => (a -> Bool) -> (a -> m a) -> (a -> m a) doWhile p t =- let recurse x = t x >>= \l -> if p l then recurse l else return l- in recurse+ let recourse x = t x >>= \l -> if p l then recourse l else return l+ in recourse {- | While loop with a priori check.@@ -40,8 +40,8 @@ -} while :: Monad m => (a -> Bool) -> (a -> m a) -> (a -> m a) while p t =- let recurse x = if p x then t x >>= recurse else return x- in recurse+ let recourse x = if p x then t x >>= recourse else return x+ in recourse whileTrace :: Monad m => (a -> m Bool) -> m a -> m [a]
src/Numeric/Probability/Random.hs view
@@ -7,7 +7,7 @@ import qualified System.Random as Random import System.Random (Random, ) -import Control.Monad.State (State(State), evalState, )+import Control.Monad.Trans.State (State, state, evalState, ) import qualified System.IO as IO import Prelude hiding (print)@@ -29,7 +29,7 @@ randomR :: Random.Random a => (a, a) -> T a randomR rng =- Cons (State (Random.randomR rng))+ Cons (state (Random.randomR rng)) {- | Run random action in 'IO' monad.
src/Numeric/Probability/Show.hs view
@@ -1,16 +1,12 @@ module Numeric.Probability.Show where showL :: Show a => Int -> a -> String-showL n x = s++rep (n-length s) ' '+showL n x = s ++ replicate (n-length s) ' ' where s=show x showR :: Show a => Int -> a -> String-showR n x = rep (n-length s) ' '++s+showR n x = replicate (n-length s) ' ' ++ s where s=show x --showP :: Float -> String --showP f = showR 3 (round (f*100))++"%"--rep :: Int -> a -> [a]-rep n x = take n (repeat x)-