Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Inference.Conjugate
Synopsis
- class Distribution a where
- newtype AsPrior p = AsPrior p
- class (Distribution p, Distribution l, Support p ~ Params l) => Conjugate p l where
- priorSingleton :: p
- updatePrior :: l -> Params p -> Support l -> Params p
- predLogP :: l -> Params p -> Support l -> Double
- type family Hyper (a :: k) :: Type
- type family Probs (a :: k) :: Type
- newtype HyperRep p = HyperRep {}
- newtype ProbsRep p = ProbsRep {}
- class Jeffreys a where
- jeffreysPrior :: Hyper a
- class GJeffreys t where
- gjeffreysPrior :: forall p. t p
- class Uniform a where
- uniformPrior :: Hyper a
- class GUniform t where
- guniformPrior :: forall p. t p
- class Prior a where
- sampleProbs :: PrimMonad m => Hyper a -> Prob m (Probs a)
- class GPrior i o where
- gsampleProbs :: forall m p. PrimMonad m => i p -> Prob m (o p)
- type Accessor r p = forall f. Lens' (r f) (f p)
- class Monad m => RandomInterpreter m r | m -> r where
- type SampleCtx m a :: Constraint
- sampleValue :: (Conjugate p l, SampleCtx m l) => String -> l -> Accessor r p -> m (Support l)
- sampleConst :: (Distribution d, SampleCtx m d) => String -> d -> Params d -> m (Support d)
- permutationPlate :: Ord a => Int -> m a -> m [a]
- newtype Trace (r :: (Type -> Type) -> Type) = Trace {}
- observeValue :: (Conjugate p l, Typeable (Support l), Monad m) => String -> l -> Accessor r p -> Support l -> StateT (Trace r) m ()
- observeConst :: (Distribution d, Typeable (Support d), Monad m) => String -> d -> Params d -> Support d -> StateT (Trace r) m ()
- takeTrace :: Typeable a => Trace r -> Maybe (a, Trace r)
- newtype SampleI m r a = SampleI (ReaderT (r ProbsRep) (Prob m) a)
- sampleResult :: p ProbsRep -> SampleI m p a -> Gen (PrimState m) -> m a
- newtype TraceI m r a = TraceI (ReaderT (r ProbsRep) (StateT (Trace r) (Prob m)) a)
- sampleTrace :: r ProbsRep -> TraceI m r a -> Gen (PrimState m) -> m (a, Trace r)
- newtype EvalTraceI r a = EvalTraceI (ReaderT (r ProbsRep) (StateT (Trace r, Double) Maybe) a)
- runTraceLogP :: r ProbsRep -> Trace r -> EvalTraceI r a -> Maybe (a, (Trace r, Double))
- evalTraceLogP :: r ProbsRep -> Trace r -> EvalTraceI r a -> Maybe (a, Double)
- newtype EvalPredTraceI r a = EvalPredTraceI (ReaderT (r HyperRep) (StateT (Trace r, Double) Maybe) a)
- runTracePredLogP :: r HyperRep -> Trace r -> EvalPredTraceI r a -> Maybe (a, (Trace r, Double))
- evalTracePredLogP :: r HyperRep -> Trace r -> EvalPredTraceI r a -> Maybe (a, Double)
- newtype UpdatePriorsI r a = UpdatePriorsI (StateT (Trace r, r HyperRep) Maybe a)
- getPosterior :: r HyperRep -> Trace r -> UpdatePriorsI r a -> Maybe (r HyperRep)
- newtype ShowTraceI r a = ShowTraceI (MaybeT (WriterT String (State (Trace r))) a)
- showTraceItem :: forall l r. (Show (Support l), Typeable l, Typeable (Support l)) => String -> ShowTraceI r (Support l)
- showTrace :: Trace r -> ShowTraceI r a -> (Maybe a, String)
- printTrace :: Trace r -> ShowTraceI r a -> IO ()
- newtype TraceTraceI r a = TraceTraceI (State (Trace r) a)
- traceTraceItem :: forall l r. (Show (Support l), Typeable l, Typeable (Support l)) => String -> TraceTraceI r (Support l)
- traceTrace :: Trace r -> TraceTraceI r a -> a
- data Beta = Beta
- data Bernoulli = Bernoulli
- newtype Binomial = Binomial Int
- data Categorical n = Categorical
- data Dirichlet n = Dirichlet
- data Geometric0 = Geometric0
- data Geometric1 = Geometric1
Documentation
class Distribution a where Source #
Describes a family of distributions with a fixed form.
For example, a Bernoulli
distribution is parameterized by a probability p
and produces binary samples
(True
with probability p
, False
with probability 1-p
).
Its Distribution
instance is:
> instance Distribution Bernoulli where
> type Params Bernoulli = Double
> type Support Bernoulli = Bool
> distSample _ = uncurry bernoulli
> distLogP _ p True = log p
> distLogP _ p False = log (1 - p)
Instances
A type-level marker for treating a distribution as a prior.
Constructors
AsPrior p |
Instances
Jeffreys (AsPrior Beta) Source # | |
Defined in Inference.Conjugate | |
KnownNat n => Jeffreys (AsPrior (Dirichlet n) :: Type) Source # | |
Defined in Inference.Conjugate | |
Prior (AsPrior Beta) Source # | |
Prior (AsPrior (Dirichlet n) :: Type) Source # | |
Uniform (AsPrior Beta) Source # | |
Defined in Inference.Conjugate | |
KnownNat n => Uniform (AsPrior (Dirichlet n) :: Type) Source # | |
Defined in Inference.Conjugate | |
type Hyper (AsPrior p :: Type) Source # | |
Defined in Inference.Conjugate | |
type Probs (AsPrior p :: Type) Source # | |
Defined in Inference.Conjugate |
class (Distribution p, Distribution l, Support p ~ Params l) => Conjugate p l where Source #
Marks two distributions as a conjugate pair of prior and likelihood.
The property of such a pair is that the posterior has the same form as the prior
(including the same Params
and Support
),
and that its parameters can be obtained analytically from the parameters of the prior
and a set of observations.
The class method updatePrior
returns the parameters of the posterior
given the prior parameters after a single observation.
Methods
Arguments
:: p | provides a singleton instance of the prior distribution in order to make sampling from priors easier. |
updatePrior :: l -> Params p -> Support l -> Params p Source #
Instances
Conjugate Beta Bernoulli Source # | |
Conjugate Beta Binomial Source # | |
Conjugate Beta Geometric0 Source # | |
Defined in Inference.Conjugate Methods priorSingleton :: Beta Source # updatePrior :: Geometric0 -> Params Beta -> Support Geometric0 -> Params Beta Source # predLogP :: Geometric0 -> Params Beta -> Support Geometric0 -> Double Source # | |
Conjugate Beta Geometric1 Source # | |
Defined in Inference.Conjugate Methods priorSingleton :: Beta Source # updatePrior :: Geometric1 -> Params Beta -> Support Geometric1 -> Params Beta Source # predLogP :: Geometric1 -> Params Beta -> Support Geometric1 -> Double Source # | |
Conjugate (Dirichlet n) (Categorical n) Source # | |
Defined in Inference.Conjugate Methods priorSingleton :: Dirichlet n Source # updatePrior :: Categorical n -> Params (Dirichlet n) -> Support (Categorical n) -> Params (Dirichlet n) Source # predLogP :: Categorical n -> Params (Dirichlet n) -> Support (Categorical n) -> Double Source # |
Instances
Instances
Prior (AsPrior p) => GPrior (K1 i (HyperRep p) :: k -> Type) (K1 i (ProbsRep p) :: k -> Type) Source # | |
(Prior k2, k2 HyperRep ~ Hyper k2, k2 ProbsRep ~ Probs k2) => GPrior (K1 i (k2 HyperRep) :: k1 -> Type) (K1 i (k2 ProbsRep) :: k1 -> Type) Source # | |
Show (Probs (AsPrior p)) => Show (ProbsRep p) Source # | |
class Jeffreys a where Source #
Methods
jeffreysPrior :: Hyper a Source #
Instances
Jeffreys (AsPrior Beta) Source # | |
Defined in Inference.Conjugate | |
KnownNat n => Jeffreys (AsPrior (Dirichlet n) :: Type) Source # | |
Defined in Inference.Conjugate | |
(Generic (t HyperRep), GJeffreys (Rep (t HyperRep))) => Jeffreys (t :: (Type -> TYPE LiftedRep) -> Type) Source # | |
Defined in Inference.Conjugate Methods jeffreysPrior :: Hyper t Source # |
class GJeffreys t where Source #
Methods
gjeffreysPrior :: forall p. t p Source #
Instances
GJeffreys (U1 :: k -> Type) Source # | |
Defined in Inference.Conjugate Methods gjeffreysPrior :: forall (p :: k0). U1 p Source # | |
GJeffreys (V1 :: k -> Type) Source # | |
Defined in Inference.Conjugate Methods gjeffreysPrior :: forall (p :: k0). V1 p Source # | |
(GJeffreys ta, GJeffreys tb) => GJeffreys (ta :*: tb :: k -> Type) Source # | |
Defined in Inference.Conjugate Methods gjeffreysPrior :: forall (p :: k0). (ta :*: tb) p Source # | |
Jeffreys (AsPrior p) => GJeffreys (K1 i (HyperRep p) :: k -> Type) Source # | |
Defined in Inference.Conjugate Methods gjeffreysPrior :: forall (p0 :: k0). K1 i (HyperRep p) p0 Source # | |
(Jeffreys k2, k2 HyperRep ~ Hyper k2) => GJeffreys (K1 i (k2 HyperRep) :: k1 -> Type) Source # | |
Defined in Inference.Conjugate Methods gjeffreysPrior :: forall (p :: k). K1 i (k2 HyperRep) p Source # | |
GJeffreys t => GJeffreys (M1 i c t :: Type -> Type) Source # | |
Defined in Inference.Conjugate Methods gjeffreysPrior :: forall (p :: k). M1 i c t p Source # |
class Uniform a where Source #
Methods
uniformPrior :: Hyper a Source #
Instances
Uniform (AsPrior Beta) Source # | |
Defined in Inference.Conjugate | |
KnownNat n => Uniform (AsPrior (Dirichlet n) :: Type) Source # | |
Defined in Inference.Conjugate | |
(Generic (t HyperRep), GUniform (Rep (t HyperRep))) => Uniform (t :: (Type -> TYPE LiftedRep) -> Type) Source # | |
Defined in Inference.Conjugate Methods uniformPrior :: Hyper t Source # |
class GUniform t where Source #
Methods
guniformPrior :: forall p. t p Source #
Instances
GUniform (U1 :: k -> Type) Source # | |
Defined in Inference.Conjugate Methods guniformPrior :: forall (p :: k0). U1 p Source # | |
GUniform (V1 :: k -> Type) Source # | |
Defined in Inference.Conjugate Methods guniformPrior :: forall (p :: k0). V1 p Source # | |
(GUniform ta, GUniform tb) => GUniform (ta :*: tb :: k -> Type) Source # | |
Defined in Inference.Conjugate Methods guniformPrior :: forall (p :: k0). (ta :*: tb) p Source # | |
Uniform (AsPrior p) => GUniform (K1 i (HyperRep p) :: k -> Type) Source # | |
Defined in Inference.Conjugate Methods guniformPrior :: forall (p0 :: k0). K1 i (HyperRep p) p0 Source # | |
(Uniform k2, k2 HyperRep ~ Hyper k2) => GUniform (K1 i (k2 HyperRep) :: k1 -> Type) Source # | |
Defined in Inference.Conjugate Methods guniformPrior :: forall (p :: k). K1 i (k2 HyperRep) p Source # | |
GUniform t => GUniform (M1 i c t :: Type -> Type) Source # | |
Defined in Inference.Conjugate Methods guniformPrior :: forall (p :: k). M1 i c t p Source # |
class GPrior i o where Source #
Methods
gsampleProbs :: forall m p. PrimMonad m => i p -> Prob m (o p) Source #
Instances
GPrior (U1 :: k -> Type) (U1 :: k -> Type) Source # | |
Defined in Inference.Conjugate | |
GPrior (V1 :: k -> Type) (V1 :: k -> Type) Source # | |
Defined in Inference.Conjugate | |
(GPrior ia oa, GPrior ib ob) => GPrior (ia :*: ib :: k -> Type) (oa :*: ob :: k -> Type) Source # | |
Defined in Inference.Conjugate | |
(GPrior ia oa, GPrior ib ob) => GPrior (ia :+: ib :: k -> Type) (oa :+: ob :: k -> Type) Source # | |
Defined in Inference.Conjugate | |
Prior (AsPrior p) => GPrior (K1 i (HyperRep p) :: k -> Type) (K1 i (ProbsRep p) :: k -> Type) Source # | |
(Prior k2, k2 HyperRep ~ Hyper k2, k2 ProbsRep ~ Probs k2) => GPrior (K1 i (k2 HyperRep) :: k1 -> Type) (K1 i (k2 ProbsRep) :: k1 -> Type) Source # | |
GPrior ti to => GPrior (M1 i c ti :: k -> Type) (M1 i' c' to :: k -> Type) Source # | |
Defined in Inference.Conjugate |
class Monad m => RandomInterpreter m r | m -> r where Source #
Associated Types
type SampleCtx m a :: Constraint Source #
Methods
sampleValue :: (Conjugate p l, SampleCtx m l) => String -> l -> Accessor r p -> m (Support l) Source #
sampleConst :: (Distribution d, SampleCtx m d) => String -> d -> Params d -> m (Support d) Source #
permutationPlate :: Ord a => Int -> m a -> m [a] Source #
Instances
observeValue :: (Conjugate p l, Typeable (Support l), Monad m) => String -> l -> Accessor r p -> Support l -> StateT (Trace r) m () Source #
observeConst :: (Distribution d, Typeable (Support d), Monad m) => String -> d -> Params d -> Support d -> StateT (Trace r) m () Source #
newtype SampleI m r a Source #
Instances
Monad m => Applicative (SampleI m r) Source # | |
Defined in Inference.Conjugate | |
Functor m => Functor (SampleI m r) Source # | |
Monad m => Monad (SampleI m r) Source # | |
PrimMonad m => RandomInterpreter (SampleI m r) r Source # | |
Defined in Inference.Conjugate Methods sampleValue :: (Conjugate p l, SampleCtx (SampleI m r) l) => String -> l -> Accessor r p -> SampleI m r (Support l) Source # sampleConst :: (Distribution d, SampleCtx (SampleI m r) d) => String -> d -> Params d -> SampleI m r (Support d) Source # permutationPlate :: Ord a => Int -> SampleI m r a -> SampleI m r [a] Source # | |
type SampleCtx (SampleI m r) a Source # | |
Defined in Inference.Conjugate |
Instances
Monad m => Applicative (TraceI m r) Source # | |
Defined in Inference.Conjugate | |
Functor m => Functor (TraceI m r) Source # | |
Monad m => Monad (TraceI m r) Source # | |
PrimMonad m => RandomInterpreter (TraceI m r) r Source # | |
Defined in Inference.Conjugate Methods sampleValue :: (Conjugate p l, SampleCtx (TraceI m r) l) => String -> l -> Accessor r p -> TraceI m r (Support l) Source # sampleConst :: (Distribution d, SampleCtx (TraceI m r) d) => String -> d -> Params d -> TraceI m r (Support d) Source # permutationPlate :: Ord a => Int -> TraceI m r a -> TraceI m r [a] Source # | |
type SampleCtx (TraceI m r) l Source # | |
Defined in Inference.Conjugate |
newtype EvalTraceI r a Source #
Instances
runTraceLogP :: r ProbsRep -> Trace r -> EvalTraceI r a -> Maybe (a, (Trace r, Double)) Source #
evalTraceLogP :: r ProbsRep -> Trace r -> EvalTraceI r a -> Maybe (a, Double) Source #
newtype EvalPredTraceI r a Source #
Instances
runTracePredLogP :: r HyperRep -> Trace r -> EvalPredTraceI r a -> Maybe (a, (Trace r, Double)) Source #
evalTracePredLogP :: r HyperRep -> Trace r -> EvalPredTraceI r a -> Maybe (a, Double) Source #
newtype UpdatePriorsI r a Source #
Constructors
UpdatePriorsI (StateT (Trace r, r HyperRep) Maybe a) |
Instances
getPosterior :: r HyperRep -> Trace r -> UpdatePriorsI r a -> Maybe (r HyperRep) Source #
newtype ShowTraceI r a Source #
Instances
showTraceItem :: forall l r. (Show (Support l), Typeable l, Typeable (Support l)) => String -> ShowTraceI r (Support l) Source #
printTrace :: Trace r -> ShowTraceI r a -> IO () Source #
newtype TraceTraceI r a Source #
Constructors
TraceTraceI (State (Trace r) a) |
Instances
traceTraceItem :: forall l r. (Show (Support l), Typeable l, Typeable (Support l)) => String -> TraceTraceI r (Support l) Source #
traceTrace :: Trace r -> TraceTraceI r a -> a Source #
Constructors
Beta |
Instances
Constructors
Bernoulli |
Instances
Generic Bernoulli Source # | |
Show Bernoulli Source # | |
Distribution Bernoulli Source # | |
Defined in Inference.Conjugate | |
Eq Bernoulli Source # | |
Ord Bernoulli Source # | |
Conjugate Beta Bernoulli Source # | |
type Rep Bernoulli Source # | |
type Params Bernoulli Source # | |
Defined in Inference.Conjugate | |
type Support Bernoulli Source # | |
Defined in Inference.Conjugate |
Instances
Generic Binomial Source # | |
Show Binomial Source # | |
Distribution Binomial Source # | |
Defined in Inference.Conjugate | |
Eq Binomial Source # | |
Ord Binomial Source # | |
Defined in Inference.Conjugate | |
Conjugate Beta Binomial Source # | |
type Rep Binomial Source # | |
Defined in Inference.Conjugate | |
type Params Binomial Source # | |
Defined in Inference.Conjugate | |
type Support Binomial Source # | |
Defined in Inference.Conjugate |
data Categorical n Source #
Constructors
Categorical |
Instances
Constructors
Dirichlet |
Instances
KnownNat n => Jeffreys (AsPrior (Dirichlet n) :: Type) Source # | |
Defined in Inference.Conjugate | |
Prior (AsPrior (Dirichlet n) :: Type) Source # | |
KnownNat n => Uniform (AsPrior (Dirichlet n) :: Type) Source # | |
Defined in Inference.Conjugate | |
Generic (Dirichlet n) Source # | |
Show (Dirichlet n) Source # | |
Distribution (Dirichlet n) Source # | |
Defined in Inference.Conjugate | |
Eq (Dirichlet n) Source # | |
Ord (Dirichlet n) Source # | |
Defined in Inference.Conjugate | |
Conjugate (Dirichlet n) (Categorical n) Source # | |
Defined in Inference.Conjugate Methods priorSingleton :: Dirichlet n Source # updatePrior :: Categorical n -> Params (Dirichlet n) -> Support (Categorical n) -> Params (Dirichlet n) Source # predLogP :: Categorical n -> Params (Dirichlet n) -> Support (Categorical n) -> Double Source # | |
type Rep (Dirichlet n) Source # | |
type Params (Dirichlet n) Source # | |
Defined in Inference.Conjugate | |
type Support (Dirichlet n) Source # | |
Defined in Inference.Conjugate |
data Geometric0 Source #
Constructors
Geometric0 |
Instances
data Geometric1 Source #
Constructors
Geometric1 |