Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 20b766f2 authored by Dahua Lin's avatar Dahua Lin

initialize new API for conjugate modeling & inference

parent 3118996e
......@@ -98,6 +98,7 @@ export
cgf, # cumulant generating function
cquantile, # complementary quantile (i.e. using prob in right hand tail)
cumulant, # cumulants of distribution
complete, # turn an incomplete formulation into a complete distribution
dim, # sample dimension of multivariate distribution
entropy, # entropy of distribution in nats
fit, # fit a distribution to data (using default method)
......@@ -126,12 +127,12 @@ export
logpdf!, # evaluate log pdf to provided storage
logpmf, # log probability mass
logpmf!, # evaluate log pmf to provided storage
posterior, # get posterior distribution given prior and observed data
posterior, # get posterior distribution given prior and observed data
posterior_canon, # get the canonical form of the posterior distribution
posterior_mode, # get the mode of posterior distribution
posterior_rand, # draw samples from the posterior distribution
posterior_rand!,
posterior_make, # create a distribution/model from params obtained from posterior
posterior_sample,
posterior_randmodel,
scale, # scale parameter of a distribution
rate, # rate parameter of a distribution
sqmahal, # squared Mahalanobis distance to Gaussian center
......
# Fallback functions for conjugates
posterior(pri::Distribution, G::IncompleteFormulation, x) = posterior(pri, suffstats(G, x))
posterior(pri::Distribution, G::IncompleteFormulation, x, w) = posterior(pri, suffstats(G, x, w))
posterior_canon(pri::Distribution, G::IncompleteFormulation, x) = posterior_canon(pri, suffstats(G, x))
posterior_canon(pri::Distribution, G::IncompleteFormulation, x, w) = posterior_canon(pri, suffstats(G, x, w))
posterior_rand(pri::Distribution, s::SufficientStats) = rand(posterior(pri, s))
posterior_rand(pri::Distribution, G::IncompleteFormulation, x) = rand(posterior(pri, G, x))
posterior_rand(pri::Distribution, G::IncompleteFormulation, x, w) = rand(posterior(pri, G, x, w))
posterior{P<:Distribution}(pri::P, ss::SufficientStats) = convert(P, posterior_canon(pri, ss))
posterior{P<:Distribution}(pri::P, G::IncompleteFormulation, x) = convert(P, posterior_canon(pri, G, x))
posterior{P<:Distribution}(pri::P, G::IncompleteFormulation, x, w) = convert(P, posterior_canon(pri, G, x, w))
posterior_rand!(r::Array, pri::Distribution, s::SufficientStats) = rand!(posterior(pri, s), r)
posterior_rand!(r::Array, pri::Distribution, G::IncompleteFormulation, x) = rand!(posterior(pri, G, x), r)
posterior_rand!(r::Array, pri::Distribution, G::IncompleteFormulation, x, w) = rand!(posterior(pri, G, x, w), r)
posterior_rand(pri::Distribution, ss::SufficientStats) = rand(posterior_canon(pri, ss))
posterior_rand(pri::Distribution, G::IncompleteFormulation, x) = rand(posterior_canon(pri, G, x))
posterior_rand(pri::Distribution, G::IncompleteFormulation, x, w) = rand(posterior_canon(pri, G, x, w))
posterior_mode(pri::Distribution, s::SufficientStats) = mode(posterior(pri, s))
posterior_mode(pri::Distribution, G::IncompleteFormulation, x) = mode(posterior(pri, G, x))
posterior_mode(pri::Distribution, G::IncompleteFormulation, x, w) = mode(posterior(pri, G, x, w))
posterior_rand!(r::Array, pri::Distribution, ss::SufficientStats) = rand!(posterior_canon(pri, ss), r)
posterior_rand!(r::Array, pri::Distribution, G::IncompleteFormulation, x) = rand!(posterior_canon(pri, G, x), r)
posterior_rand!(r::Array, pri::Distribution, G::IncompleteFormulation, x, w) = rand!(posterior_canon(pri, G, x, w), r)
posterior_make{D<:Distribution}(::Type{D}, θ) = D(θ)
fit_map{D<:Distribution}(pri::Distribution, ::Type{D}, x) = posterior_make(D, posterior_mode(pri, D, x))
fit_map{D<:Distribution}(pri::Distribution, ::Type{D}, x, w) = posterior_make(D, posterior_mode(pri, D, x, w))
posterior_mode(pri::Distribution, ss::SufficientStats) = mode(posterior_canon(pri, ss))
posterior_mode(pri::Distribution, G::IncompleteFormulation, x) = mode(posterior_canon(pri, G, x))
posterior_mode(pri::Distribution, G::IncompleteFormulation, x, w) = mode(posterior_canon(pri, G, x, w))
posterior_sample{D<:Distribution}(pri::Distribution, G::Type{D}, x) = D(rand(posterior(pri, G, x))...)
posterior_sample{D<:Distribution}(pri::Distribution, G::Type{D}, x, w) = D(rand(posterior(pri, G, x, w))...)
posterior_sample{D<:Distribution,G<:Distribution}(post::D, ::Type{G}) = G(rand(post)...)
fit_map(pri::Distribution, G::IncompleteFormulation, x) = complete(G, pri, posterior_mode(pri, G, x)...)
fit_map(pri::Distribution, G::IncompleteFormulation, x, w) = complete(G, pri, posterior_mode(pri, G, x, w)...)
posterior_randmodel(pri::Distribution, G::IncompleteFormulation, x) = complete(G, pri, posterior_rand(pri, G, x)...)
posterior_randmodel(pri::Distribution, G::IncompleteFormulation, x, w) = complete(G, pri, posterior_rand(pri, G, x, w)...)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment