-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Base types and classes for statistics, sciences and humanities -- -- This library provides a set of basic types and classes for statistics, -- sciences, and the humanities. @package SciBaseTypes @version 0.1.1.0 -- | Approximate and exact limits around 0 and towards transfinite numbers. module Numeric.Limits -- | The class of limits into the transfinite. class NumericLimits x minFinite :: NumericLimits x => x maxFinite :: NumericLimits x => x -- | The smallest value /= 0 for numeric values. class NumericEpsilon x -- | Numeric epsilon. epsilon :: NumericEpsilon x => x instance Numeric.Limits.NumericEpsilon GHC.Types.Double instance Numeric.Limits.NumericLimits GHC.Types.Word instance Numeric.Limits.NumericLimits GHC.Types.Int instance Numeric.Limits.NumericLimits GHC.Types.Double -- | A set with two binary operations, one for addition (srplus), -- one for multiplication (srmul). Together with a neutral -- element for srplus, named srzero, and one for -- srmul, named srone. module Algebra.Structure.Semiring pattern V_MaxPlus :: () => Vector x_aeVt -> Vector (MaxPlus x_aeVt) pattern V_Viterbi :: () => Vector x_adOG -> Vector (Viterbi x_adOG) pattern V_MinPlus :: () => Vector x_aexN -> Vector (MinPlus x_aexN) pattern MV_MaxPlus :: () => MVector s x_aeVt -> MVector s (MaxPlus x_aeVt) pattern MV_Viterbi :: () => MVector s x_adOG -> MVector s (Viterbi x_adOG) pattern MV_MinPlus :: () => MVector s x_aexN -> MVector s (MinPlus x_aexN) -- | The Viterbi SemiRing. It maximizes over the product. newtype Viterbi x Viterbi :: x -> Viterbi x [getViterbi] :: Viterbi x -> x -- | Unicode variant of srplus. (⊕) :: Semiring a => a -> a -> a infixl 6 ⊕ -- | Unicode variant of srmul. (⊗) :: Semiring a => a -> a -> a infixl 7 ⊗ -- | times but done n times. -- -- TODO Include into type class to improve performance nTimes :: Semiring a => Int -> a -> a -- | The tropical MinPlus SemiRing. It minimizes over the sum. newtype MinPlus x MinPlus :: x -> MinPlus x [getMinPlus] :: MinPlus x -> x -- | The tropical MaxPlus SemiRing. It maximizes over the sum. newtype MaxPlus x MaxPlus :: x -> MaxPlus x [getMaxPlus] :: MaxPlus x -> x -- | The generic semiring, defined over two Semigroup and -- Monoid constructions. -- -- It can be used like this: zero ∷ GSemiring Min Sum Int == -- maxBound one ∷ GSemiring Min Sum Int == 0 -- -- It is generally useful to still provide explicit instances, since -- Min requires a Bounded instance. newtype GSemiring (zeroMonoid :: * -> *) (oneMonoid :: * -> *) (x :: *) GSemiring :: x -> GSemiring (zeroMonoid :: * -> *) (oneMonoid :: * -> *) (x :: *) [getSemiring] :: GSemiring (zeroMonoid :: * -> *) (oneMonoid :: * -> *) (x :: *) -> x -- | The class of semirings (types with two binary operations and two -- respective identities). One can think of a semiring as two monoids of -- the same underlying type, with the first being commutative. In the -- documentation, you will often see the first monoid being referred to -- as additive, and the second monoid being referred to as -- multiplicative, a typical convention when talking about -- semirings. -- -- For any type R with a Num instance, the additive monoid is (R, -- +, 0) and the multiplicative monoid is (R, *, 1). -- -- For Bool, the additive monoid is (Bool, ||, -- False) and the multiplicative monoid is (Bool, -- &&, True). -- -- Instances should satisfy the following laws: -- -- class Semiring a plus :: Semiring a => a -> a -> a zero :: Semiring a => a times :: Semiring a => a -> a -> a one :: Semiring a => a fromNatural :: Semiring a => Natural -> a infixl 7 `times` infixl 6 `plus` instance GHC.Generics.Generic (Algebra.Structure.Semiring.GSemiring zeroMonoid oneMonoid x) instance GHC.Show.Show x => GHC.Show.Show (Algebra.Structure.Semiring.GSemiring zeroMonoid oneMonoid x) instance GHC.Read.Read x => GHC.Read.Read (Algebra.Structure.Semiring.GSemiring zeroMonoid oneMonoid x) instance GHC.Classes.Ord x => GHC.Classes.Ord (Algebra.Structure.Semiring.GSemiring zeroMonoid oneMonoid x) instance GHC.Classes.Eq x => GHC.Classes.Eq (Algebra.Structure.Semiring.GSemiring zeroMonoid oneMonoid x) instance Control.DeepSeq.NFData x => Control.DeepSeq.NFData (Algebra.Structure.Semiring.GSemiring zM oM x) instance Data.Aeson.Types.ToJSON.ToJSON x => Data.Aeson.Types.ToJSON.ToJSON (Algebra.Structure.Semiring.GSemiring z o x) instance Data.Aeson.Types.FromJSON.FromJSON x => Data.Aeson.Types.FromJSON.FromJSON (Algebra.Structure.Semiring.GSemiring z o x) instance (GHC.Base.Semigroup (zeroMonoid x), GHC.Base.Monoid (zeroMonoid x), GHC.Base.Semigroup (oneMonoid x), GHC.Base.Monoid (oneMonoid x), GHC.Types.Coercible (zeroMonoid x) (Algebra.Structure.Semiring.GSemiring zeroMonoid oneMonoid x), GHC.Types.Coercible (oneMonoid x) (Algebra.Structure.Semiring.GSemiring zeroMonoid oneMonoid x)) => Data.Semiring.Semiring (Algebra.Structure.Semiring.GSemiring zeroMonoid oneMonoid x) instance Data.Vector.Unboxed.Base.Unbox x => Data.Vector.Unboxed.Base.Unbox (Algebra.Structure.Semiring.MaxPlus x) instance Data.Vector.Unboxed.Base.Unbox x => Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Algebra.Structure.Semiring.MaxPlus x) instance Data.Vector.Unboxed.Base.Unbox x => Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Algebra.Structure.Semiring.MaxPlus x) instance Control.DeepSeq.NFData x => Control.DeepSeq.NFData (Algebra.Structure.Semiring.MaxPlus x) instance Data.Aeson.Types.ToJSON.ToJSON x => Data.Aeson.Types.ToJSON.ToJSON (Algebra.Structure.Semiring.MaxPlus x) instance Data.Aeson.Types.FromJSON.FromJSON x => Data.Aeson.Types.FromJSON.FromJSON (Algebra.Structure.Semiring.MaxPlus x) instance Numeric.Limits.NumericLimits x => Numeric.Limits.NumericLimits (Algebra.Structure.Semiring.MaxPlus x) instance Data.Info.Info x => Data.Info.Info (Algebra.Structure.Semiring.MaxPlus x) instance (GHC.Classes.Ord x, Data.Semiring.Semiring x, Numeric.Limits.NumericLimits x) => Data.Semiring.Semiring (Algebra.Structure.Semiring.MaxPlus x) instance GHC.Float.RealFloat a => Data.Semiring.Semiring (Numeric.Log.Log a) instance GHC.Num.Num x => GHC.Num.Num (Algebra.Structure.Semiring.MaxPlus x) instance GHC.Generics.Generic1 Algebra.Structure.Semiring.MaxPlus instance GHC.Generics.Generic (Algebra.Structure.Semiring.MaxPlus x) instance GHC.Enum.Bounded x => GHC.Enum.Bounded (Algebra.Structure.Semiring.MaxPlus x) instance GHC.Show.Show x => GHC.Show.Show (Algebra.Structure.Semiring.MaxPlus x) instance GHC.Read.Read x => GHC.Read.Read (Algebra.Structure.Semiring.MaxPlus x) instance GHC.Classes.Ord x => GHC.Classes.Ord (Algebra.Structure.Semiring.MaxPlus x) instance GHC.Classes.Eq x => GHC.Classes.Eq (Algebra.Structure.Semiring.MaxPlus x) instance Data.Vector.Unboxed.Base.Unbox x => Data.Vector.Unboxed.Base.Unbox (Algebra.Structure.Semiring.MinPlus x) instance Data.Vector.Unboxed.Base.Unbox x => Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Algebra.Structure.Semiring.MinPlus x) instance Data.Vector.Unboxed.Base.Unbox x => Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Algebra.Structure.Semiring.MinPlus x) instance Control.DeepSeq.NFData x => Control.DeepSeq.NFData (Algebra.Structure.Semiring.MinPlus x) instance Data.Aeson.Types.ToJSON.ToJSON x => Data.Aeson.Types.ToJSON.ToJSON (Algebra.Structure.Semiring.MinPlus x) instance Data.Aeson.Types.FromJSON.FromJSON x => Data.Aeson.Types.FromJSON.FromJSON (Algebra.Structure.Semiring.MinPlus x) instance Numeric.Limits.NumericLimits x => Numeric.Limits.NumericLimits (Algebra.Structure.Semiring.MinPlus x) instance (GHC.Classes.Ord x, Data.Semiring.Semiring x, Numeric.Limits.NumericLimits x) => Data.Semiring.Semiring (Algebra.Structure.Semiring.MinPlus x) instance GHC.Num.Num x => GHC.Num.Num (Algebra.Structure.Semiring.MinPlus x) instance GHC.Generics.Generic1 Algebra.Structure.Semiring.MinPlus instance GHC.Generics.Generic (Algebra.Structure.Semiring.MinPlus x) instance GHC.Enum.Bounded x => GHC.Enum.Bounded (Algebra.Structure.Semiring.MinPlus x) instance GHC.Show.Show x => GHC.Show.Show (Algebra.Structure.Semiring.MinPlus x) instance GHC.Read.Read x => GHC.Read.Read (Algebra.Structure.Semiring.MinPlus x) instance GHC.Classes.Ord x => GHC.Classes.Ord (Algebra.Structure.Semiring.MinPlus x) instance GHC.Classes.Eq x => GHC.Classes.Eq (Algebra.Structure.Semiring.MinPlus x) instance Data.Vector.Unboxed.Base.Unbox x => Data.Vector.Unboxed.Base.Unbox (Algebra.Structure.Semiring.Viterbi x) instance Data.Vector.Unboxed.Base.Unbox x => Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Algebra.Structure.Semiring.Viterbi x) instance Data.Vector.Unboxed.Base.Unbox x => Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Algebra.Structure.Semiring.Viterbi x) instance Control.DeepSeq.NFData x => Control.DeepSeq.NFData (Algebra.Structure.Semiring.Viterbi x) instance Data.Aeson.Types.ToJSON.ToJSON x => Data.Aeson.Types.ToJSON.ToJSON (Algebra.Structure.Semiring.Viterbi x) instance Data.Aeson.Types.FromJSON.FromJSON x => Data.Aeson.Types.FromJSON.FromJSON (Algebra.Structure.Semiring.Viterbi x) instance (GHC.Classes.Ord x, Data.Semiring.Semiring x) => Data.Semiring.Semiring (Algebra.Structure.Semiring.Viterbi x) instance GHC.Num.Num x => GHC.Num.Num (Algebra.Structure.Semiring.Viterbi x) instance GHC.Generics.Generic1 Algebra.Structure.Semiring.Viterbi instance GHC.Generics.Generic (Algebra.Structure.Semiring.Viterbi x) instance GHC.Enum.Bounded x => GHC.Enum.Bounded (Algebra.Structure.Semiring.Viterbi x) instance GHC.Show.Show x => GHC.Show.Show (Algebra.Structure.Semiring.Viterbi x) instance GHC.Read.Read x => GHC.Read.Read (Algebra.Structure.Semiring.Viterbi x) instance GHC.Classes.Ord x => GHC.Classes.Ord (Algebra.Structure.Semiring.Viterbi x) instance GHC.Classes.Eq x => GHC.Classes.Eq (Algebra.Structure.Semiring.Viterbi x) -- | Discretized floating point numbers, where the scaling factor is kept -- as two phantom types denoting the rational number used for scaling. module Numeric.Discretized -- | Some discretizations are of the type ln 2 / 2 (PAM -- matrices in Blast for example). Using this type, we can annotate as -- follows: Discretized (RTyLn 2 :% RTyId 2). -- -- One may use Unknown if the scale is not known. For example, -- the blast matrices use different scales internally and one needs to -- read the header to get the scale. data RatioTy a RTyExp :: a -> RatioTy a RTyId :: a -> RatioTy a RTyLn :: a -> RatioTy a RTyPlus :: RatioTy a -> RatioTy a -> RatioTy a RTyTimes :: RatioTy a -> RatioTy a -> RatioTy a Unknown :: RatioTy a class RatioTyConstant a ratioTyConstant :: RatioTyConstant a => Proxy a -> Ratio Integer -- | A discretized value takes a floating point number n and -- produces a discretized value. The actual discretization formula is -- given on the type level, freeing us from having to carry around some -- scaling function. -- -- Typically, one might use types likes 100, (100 :% -- 1), or (RTyLn 2 :% RTyId 2). -- -- The main use of a Discretized value is to enable calculations -- with Int while somewhat pretending to use floating point -- values. -- -- Be careful with certain operations like (*) as they will -- easily cause the numbers to arbitrarily wrong. (+) and -- (-) are fine, however. -- -- NOTE Export and import of data is in the form of floating points, -- which can lead to additional loss of precision if one is careless! -- -- TODO fast Show methods required! -- -- TODO blaze stuff? -- -- TODO We might want to discretize LogDomain style values. This -- requires some thought on in which direction to wrap. Maybe, we want to -- log-domain Discretized values, which probably just works. newtype Discretized (b :: k) Discretized :: Int -> Discretized (b :: k) [getDiscretized] :: Discretized (b :: k) -> Int fromUnknown :: Discretized Unknown -> Discretized t -- | Discretizes any Real a into the Discretized value. -- This conversion is lossy and uses a type-level rational of -- u :% l! discretizeRatio :: forall a u l. (Real a, KnownNat u, KnownNat l) => a -> Discretized ((u :: Nat) :% (l :: Nat)) instance forall k (t :: k). Data.Vector.Unboxed.Base.Unbox (Numeric.Discretized.Discretized t) instance forall k (t :: k). Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Numeric.Discretized.Discretized t) instance forall k (t :: k). Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Numeric.Discretized.Discretized t) instance forall k (t :: k). Control.DeepSeq.NFData (Numeric.Discretized.Discretized t) instance forall k (t :: k). Data.Binary.Class.Binary (Numeric.Discretized.Discretized t) instance forall k (t :: k). Data.Serialize.Serialize (Numeric.Discretized.Discretized t) instance forall k (t :: k). Data.Hashable.Class.Hashable (Numeric.Discretized.Discretized t) instance (GHC.TypeNats.KnownNat k, GHC.TypeNats.KnownNat l) => Data.Aeson.Types.ToJSON.ToJSON (Numeric.Discretized.Discretized (k 'GHC.Real.:% l)) instance (GHC.TypeNats.KnownNat k, GHC.TypeNats.KnownNat l) => Data.Aeson.Types.FromJSON.FromJSON (Numeric.Discretized.Discretized (k 'GHC.Real.:% l)) instance GHC.Num.Num (Numeric.Discretized.Discretized 'Numeric.Discretized.Unknown) instance (GHC.TypeNats.KnownNat u, GHC.TypeNats.KnownNat l) => GHC.Num.Num (Numeric.Discretized.Discretized (u 'GHC.Real.:% l)) instance forall k (b :: k). GHC.Enum.Enum (Numeric.Discretized.Discretized b) instance (GHC.TypeNats.KnownNat u, GHC.TypeNats.KnownNat l) => GHC.Real.Fractional (Numeric.Discretized.Discretized (u 'GHC.Real.:% l)) instance (GHC.TypeNats.KnownNat u, GHC.TypeNats.KnownNat l) => GHC.Real.Real (Numeric.Discretized.Discretized (u 'GHC.Real.:% l)) instance forall k1 (k2 :: k1). GHC.Num.Num (Numeric.Discretized.Discretized k2) => Data.Semiring.Semiring (Numeric.Discretized.Discretized k2) instance forall k (t :: k). Numeric.Limits.NumericLimits (Numeric.Discretized.Discretized t) instance forall k (b :: k). GHC.Read.Read (Numeric.Discretized.Discretized b) instance forall k (b :: k). GHC.Generics.Generic (Numeric.Discretized.Discretized b) instance forall k (b :: k). GHC.Classes.Ord (Numeric.Discretized.Discretized b) instance forall k (b :: k). GHC.Classes.Eq (Numeric.Discretized.Discretized b) instance forall k (b :: k). GHC.Show.Show (Numeric.Discretized.Discretized b) instance forall k (b :: k). Data.Info.Info (Numeric.Discretized.Discretized b) instance (GHC.TypeNats.KnownNat k, GHC.TypeNats.KnownNat l) => Numeric.Discretized.RatioTyConstant (k 'GHC.Real.:% l) instance GHC.TypeNats.KnownNat k => Numeric.Discretized.RatioTyConstant ('Numeric.Discretized.RTyExp k) instance GHC.TypeNats.KnownNat k => Numeric.Discretized.RatioTyConstant ('Numeric.Discretized.RTyId k) instance GHC.TypeNats.KnownNat k => Numeric.Discretized.RatioTyConstant ('Numeric.Discretized.RTyLn k) instance forall k (a :: Numeric.Discretized.RatioTy k) (b :: Numeric.Discretized.RatioTy k). (Numeric.Discretized.RatioTyConstant a, Numeric.Discretized.RatioTyConstant b) => Numeric.Discretized.RatioTyConstant ('Numeric.Discretized.RTyPlus a b) instance forall k (a :: Numeric.Discretized.RatioTy k) (b :: Numeric.Discretized.RatioTy k). (Numeric.Discretized.RatioTyConstant a, Numeric.Discretized.RatioTyConstant b) => Numeric.Discretized.RatioTyConstant ('Numeric.Discretized.RTyTimes a b) -- | This module provides log-domain functionality. Ed Kmett provides, with -- log-domain, a generic way to handle numbers in the -- log-domain, some which is used under the hood here. We want some -- additional type safety and also connect with the SemiRing -- module. module Numeric.LogDomain -- | Instances for LogDomain x should be for specific types. class LogDomain x where { -- | The type family to connect a type x with the type Ln -- x in the log-domain. type family Ln x :: *; } -- | Transport a value in x into the log-domain. logdom -- should throw an exception if log x is not valid. logdom :: (LogDomain x, MonadError String m) => x -> m (Ln x) -- | Unsafely transport x into the log-domain. unsafelogdom :: LogDomain x => x -> Ln x -- | Transport a value Ln x back into the linear domain -- x. lindom :: LogDomain x => Ln x -> x -- | This is similar to sum but requires only one pass over the -- data. It will be useful if the first two elements in the stream are -- large. If the user has some control over how the stream is generated, -- this function might show better performance than sum and better -- numeric stability than 'fold 0 (+)' -- -- TODO this needs to be benchmarked against fold 0 (+), since -- in DnaProteinAlignment sumS seems to be slower! sumS :: (Monad m, Ord a, RealFloat a, Show a) => Log a -> Stream m (Log a) -> m (Log a) -- | log-sum-exp for streams, without incurring examining the -- stream twice, but with the potential for numeric problems. In -- pricinple, the numeric error of this function should be better than -- individual binary function application and worse than an optimized -- sum function. -- -- Needs to be written in direct style, as otherwise any constructors (to -- tell us if we collected two elements already) remain. logsumexpS :: (Monad m, Ord a, Num a, Floating a) => Stream m a -> m a instance Numeric.LogDomain.LogDomain GHC.Types.Double -- | Provides newtypes for odds, log-odds, and discretized versions. -- -- TODO This is currently quite ad-hoc and needs better formalization. In -- particular in terms of wrapping and usage of Num and -- Semiring. module Statistics.Odds -- | Odds. newtype Odds Odds :: Double -> Odds [getOdds] :: Odds -> Double -- | Encodes log-odds that have been rounded or clamped to integral -- numbers. One advantage this provides is more efficient -- "maximum/minimum" calculations compared to using Doubles. -- -- Note that these are "explicit" log-odds. Each numeric operation uses -- the underlying operation on Int. If you want automatic -- handling, choose Log Odds. newtype DiscLogOdds (t :: k) DiscLogOdds :: Discretized t -> DiscLogOdds (t :: k) [getDiscLogOdds] :: DiscLogOdds (t :: k) -> Discretized t instance forall k (t :: k). Data.Vector.Unboxed.Base.Unbox (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). Data.Binary.Class.Binary (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). Data.Serialize.Serialize (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). Data.Hashable.Class.Hashable (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). Data.Aeson.Types.ToJSON.ToJSON (Numeric.Discretized.Discretized t) => Data.Aeson.Types.ToJSON.ToJSON (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). Data.Aeson.Types.FromJSON.FromJSON (Numeric.Discretized.Discretized t) => Data.Aeson.Types.FromJSON.FromJSON (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). Control.DeepSeq.NFData (Numeric.Discretized.Discretized t) => Control.DeepSeq.NFData (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). Numeric.Limits.NumericLimits (Numeric.Discretized.Discretized t) => Numeric.Limits.NumericLimits (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). Data.Info.Info (Statistics.Odds.DiscLogOdds t) instance GHC.Num.Num Statistics.Odds.Odds instance GHC.Read.Read Statistics.Odds.Odds instance GHC.Show.Show Statistics.Odds.Odds instance GHC.Classes.Ord Statistics.Odds.Odds instance GHC.Classes.Eq Statistics.Odds.Odds instance GHC.Generics.Generic Statistics.Odds.Odds instance forall k (t :: k). GHC.Read.Read (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). GHC.Show.Show (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). GHC.Classes.Ord (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). GHC.Classes.Eq (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). GHC.Generics.Generic (Statistics.Odds.DiscLogOdds t) instance Data.Semiring.Semiring Statistics.Odds.Odds instance forall k (t :: k). GHC.Num.Num (Numeric.Discretized.Discretized t) => GHC.Num.Num (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). Data.Semiring.Semiring (Numeric.Discretized.Discretized t) => Data.Semiring.Semiring (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). GHC.Real.Fractional (Numeric.Discretized.Discretized t) => GHC.Real.Fractional (Statistics.Odds.DiscLogOdds t) instance forall k (t :: k). GHC.Real.Real (Numeric.Discretized.Discretized t) => GHC.Real.Real (Statistics.Odds.DiscLogOdds t) instance Control.DeepSeq.NFData Statistics.Odds.Odds -- | Probability-related types. -- -- TODO instances for serialization and further stuff TODO vector -- instances module Statistics.Probability data IsNormalized Normalized :: IsNormalized NotNormalized :: IsNormalized -- | Prob wraps a Double that encodes probabilities. If -- Prob is tagged as Normalized, the contained values -- are in the range [0,...,1], otherwise they are in the range -- [0,...,∞]. newtype Probability (n :: IsNormalized) x Prob :: x -> Probability (n :: IsNormalized) x [getProb] :: Probability (n :: IsNormalized) x -> x -- | Turns a value into a normalized probability. error if the -- value is not in the range [0,...,1]. prob :: (Ord x, Num x, Show x) => x -> Probability Normalized x -- | Simple wrapper around Probability that fixes -- non-normalization. prob' :: (Ord x, Num x, Show x) => x -> Probability NotNormalized x -- | This simple function represents probabilities with characters between -- '0' 0.0 -- 0.05 up to '9' 0.85 -- 0.95 and finally -- * for >0.95. probabilityToChar :: (Num k, RealFrac k) => Probability Normalized k -> Char instance GHC.Enum.Enum x => GHC.Enum.Enum (Statistics.Probability.Probability n x) instance GHC.Num.Num x => GHC.Num.Num (Statistics.Probability.Probability n x) instance GHC.Real.Fractional x => GHC.Real.Fractional (Statistics.Probability.Probability n x) instance GHC.Float.Floating x => GHC.Float.Floating (Statistics.Probability.Probability n x) instance GHC.Real.Real x => GHC.Real.Real (Statistics.Probability.Probability n x) instance GHC.Real.RealFrac x => GHC.Real.RealFrac (Statistics.Probability.Probability n x) instance GHC.Float.RealFloat x => GHC.Float.RealFloat (Statistics.Probability.Probability n x) instance Data.Vector.Unboxed.Base.Unbox x => Data.Vector.Unboxed.Base.Unbox (Statistics.Probability.Probability n x) instance Data.Vector.Unboxed.Base.Unbox x => Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Statistics.Probability.Probability n x) instance Data.Vector.Unboxed.Base.Unbox x => Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Statistics.Probability.Probability n x) instance Data.Aeson.Types.ToJSON.ToJSON x => Data.Aeson.Types.ToJSON.ToJSON (Statistics.Probability.Probability n x) instance Data.Aeson.Types.FromJSON.FromJSON x => Data.Aeson.Types.FromJSON.FromJSON (Statistics.Probability.Probability n x) instance GHC.Num.Num r => Data.Semiring.Semiring (Statistics.Probability.Probability n r) instance GHC.Generics.Generic (Statistics.Probability.Probability n x) instance GHC.Read.Read x => GHC.Read.Read (Statistics.Probability.Probability n x) instance GHC.Show.Show x => GHC.Show.Show (Statistics.Probability.Probability n x) instance GHC.Classes.Ord x => GHC.Classes.Ord (Statistics.Probability.Probability n x) instance GHC.Classes.Eq x => GHC.Classes.Eq (Statistics.Probability.Probability n x) instance Control.DeepSeq.NFData x => Control.DeepSeq.NFData (Statistics.Probability.Probability n x) -- | This module provides generic functionality to deal with ensembles in -- statistical mechanics. module StatisticalMechanics.Ensemble -- | The state probability functions provide conversion from some types -- a into non-normalized probabilities. For "real" applications, -- using the logProbability function is preferred. This -- functions allows for easy abstraction when types a are given -- as fractions of some actual value (say: deka-cal), or are discretized. -- -- The returned values are not normalized, because we do not now the -- total evidence Z until integration over all states has -- happened -- which is not feasible in a number of problems. -- -- TODO replace () with temperature and results with -- non-normalized P or LogP, depending. At some point -- we want to have type-level physical quantities, hence the need for the -- second type. class StateProbability a -- | Given a temperature and a state "energy", return the corresponding -- non-normalized probability. stateProbability :: StateProbability a => Double -> a -> Probability NotNormalized Double stateLogProbability :: StateProbability a => Double -> a -> Log (Probability NotNormalized Double) instance StatisticalMechanics.Ensemble.StateProbability GHC.Types.Double