{-# LANGUAGE
MultiParamTypeClasses,
FlexibleInstances, FlexibleContexts,
UndecidableInstances,
TemplateHaskell
#-}moduleData.Random.Distribution.BernoulliwhereimportData.Random.Internal.THimportData.Random.RVarimportData.Random.DistributionimportData.Random.Distribution.UniformimportData.RatioimportData.Complex-- |Generate a Bernoulli variate with the given probability. For @Bool@ results,-- @bernoulli p@ will return True (p*100)% of the time and False otherwise.-- For numerical types, True is replaced by 1 and False by 0.bernoulli::Distribution(Bernoullib)a=>b->RVarabernoullip=rvar(Bernoullip)-- |Generate a Bernoulli process with the given probability. For @Bool@ results,-- @bernoulli p@ will return True (p*100)% of the time and False otherwise.-- For numerical types, True is replaced by 1 and False by 0.bernoulliT::Distribution(Bernoullib)a=>b->RVarTmabernoulliTp=rvarT(Bernoullip)-- |A random variable whose value is 'True' the given fraction of the time-- and 'False' the rest.boolBernoulli::(Fractionala,Orda,DistributionStdUniforma)=>a->RVarTmBoolboolBernoullip=dox<-stdUniformTreturn(x<=p)boolBernoulliCDF::(Reala)=>a->Bool->DoubleboolBernoulliCDF_True=1boolBernoulliCDFpFalse=(1-realToFracp)-- | @generalBernoulli t f p@ generates a random variable whose value is @t@-- with probability @p@ and @f@ with probability @1-p@.generalBernoulli::Distribution(Bernoullib)Bool=>a->a->b->RVarTmageneralBernoulliftp=dox<-bernoulliTpreturn(ifxthentelsef)generalBernoulliCDF::CDF(Bernoullib)Bool=>(a->a->Bool)->a->a->b->a->DoublegeneralBernoulliCDFgteftpx|f`gte`t=error"generalBernoulliCDF: f >= t"|x`gte`t=cdf(Bernoullip)True|x`gte`f=cdf(Bernoullip)False|otherwise=0dataBernoulliba=Bernoullibinstance(Fractionalb,Ordb,DistributionStdUniformb)=>Distribution(Bernoullib)BoolwherervarT(Bernoullip)=boolBernoullipinstance(Distribution(Bernoullib)Bool,Realb)=>CDF(Bernoullib)Boolwherecdf(Bernoullip)=boolBernoulliCDFp$(replicateInstances''IntintegralTypes[d|instanceDistribution(Bernoullib)Bool=>Distribution(Bernoullib)IntwherervarT(Bernoullip)=generalBernoulli01pinstanceCDF(Bernoullib)Bool=>CDF(Bernoullib)Intwherecdf(Bernoullip)=generalBernoulliCDF(>=)01p|])$(replicateInstances''FloatrealFloatTypes[d|instanceDistribution(Bernoullib)Bool=>Distribution(Bernoullib)FloatwherervarT(Bernoullip)=generalBernoulli01pinstanceCDF(Bernoullib)Bool=>CDF(Bernoullib)Floatwherecdf(Bernoullip)=generalBernoulliCDF(>=)01p|])instance(Distribution(Bernoullib)Bool,Integrala)=>Distribution(Bernoullib)(Ratioa)wherervarT(Bernoullip)=generalBernoulli01pinstance(CDF(Bernoullib)Bool,Integrala)=>CDF(Bernoullib)(Ratioa)wherecdf(Bernoullip)=generalBernoulliCDF(>=)01pinstance(Distribution(Bernoullib)Bool,RealFloata)=>Distribution(Bernoullib)(Complexa)wherervarT(Bernoullip)=generalBernoulli01pinstance(CDF(Bernoullib)Bool,RealFloata)=>CDF(Bernoullib)(Complexa)wherecdf(Bernoullip)=generalBernoulliCDF(\xy->realPartx>=realParty)01p