{-# LANGUAGE MultiParamTypeClasses #-}{-# LANGUAGE FunctionalDependencies #-}{-# LANGUAGE FlexibleInstances #-}{-# LANGUAGE UndecidableInstances #-}{- |
Portability: Multi-parameter type class with functional dependency
Abstract interface to probabilistic objects
like random generators and probability distributions.
It allows to use the same code
both for computing complete distributions
and for generating random values according to the distribution.
The latter one is of course more efficient
and may be used for approximation of the distribution by simulation.
Maybe a better name is @Experiment@.
-}moduleNumeric.Probability.ObjectwhereimportqualifiedNumeric.Probability.Distribution asDistimportqualifiedNumeric.Probability.Random asRndimportqualifiedNumeric.Probability.Shape asShapeimportqualifiedNumeric.Probability.Either asPEimportqualifiedData.ListasListimportControl.Monad(liftM,)classMonadobj =>C prob obj |obj->probwherefromFrequencies ::[(a ,prob )]->obj a instanceC DoubleRnd.T wherefromFrequencies =Rnd.pick .Dist.fromFreqs instanceFractionalprob =>C prob (Dist.T prob )wherefromFrequencies =Dist.fromFreqs instanceC prob obj =>C prob (PE.EitherT b obj )wherefromFrequencies =PE.EitherT .liftMRight.fromFrequencies typeSpread obj a =[a ]->obj a shape::(C prob obj ,Fractionalprob )=>(prob ->prob )->Spread obj a shape _[]=error"Probability.shape: empty list"shapef xs =letincr =1/fromIntegral(lengthxs -1)ps =List.mapf (iterate(+incr )0)infromFrequencies (zipxs ps )linear::(C prob obj ,Fractionalprob )=>Spread obj a linear =shape Shape.linear uniform::(C prob obj ,Fractionalprob )=>Spread obj a uniform =shape Shape.uniform negExp::(C prob obj ,Floatingprob )=>Spread obj a negExp =shape Shape.negExp normal::(C prob obj ,Floatingprob )=>Spread obj a normal =shape Shape.normal enum::(C prob obj ,Floatingprob )=>[Int]->Spread obj a enum =relative .List.mapfromIntegral{- |
Give a list of frequencies, they do not need to sum up to 1.
-}relative::(C prob obj ,Floatingprob )=>[prob ]->Spread obj a relative ns =fromFrequencies .flipzipns 

AltStyle によって変換されたページ (->オリジナル) /