diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 8b11f7ee..aad7d303 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.9.3","generation_timestamp":"2023-10-17T11:12:43","documenter_version":"1.1.1"}} \ No newline at end of file +{"documenter":{"julia_version":"1.9.3","generation_timestamp":"2023-10-31T13:21:26","documenter_version":"1.1.2"}} \ No newline at end of file diff --git a/dev/examples/index.html b/dev/examples/index.html index 7a9d8f9c..7b793358 100644 --- a/dev/examples/index.html +++ b/dev/examples/index.html @@ -1,5 +1,5 @@ -Examples · ExponentialFamily.jl

Examples

Product of two probability distributions over the same variable

In this example, we'll show you how to use the ExponentialFamily package to calculate the product of probability distributions that both relate to the same variable "X". This operation results in another probability distribution, also centered around the variable "X". It's essential to note that this is distinct from multiplying probability distributions for two different variables, such as "X" and "Y", which yields a joint probability distribution. Calculating the product of two probability distributions over the same variable is a crucial step in applying Bayes' rule.

\[p(X\vert D) \propto \underbrace{p(X)p(D|X)}_{\mathrm{product~of~two~distributions}}\]

To perform this operation, the ExponentialFamily library employs the prod function. This function takes a product strategy as its first argument. For instance:

using ExponentialFamily, Distributions
+Examples · ExponentialFamily.jl

Examples

Product of two probability distributions over the same variable

In this example, we'll show you how to use the ExponentialFamily package to calculate the product of probability distributions that both relate to the same variable "X". This operation results in another probability distribution, also centered around the variable "X". It's essential to note that this is distinct from multiplying probability distributions for two different variables, such as "X" and "Y", which yields a joint probability distribution. Calculating the product of two probability distributions over the same variable is a crucial step in applying Bayes' rule.

\[p(X\vert D) \propto \underbrace{p(X)p(D|X)}_{\mathrm{product~of~two~distributions}}\]

To perform this operation, the ExponentialFamily library employs the prod function. This function takes a product strategy as its first argument. For instance:

using ExponentialFamily, Distributions, BayesBase
 
 prior = Bernoulli(0.5)
 likelihood = Bernoulli(0.6)
@@ -10,7 +10,7 @@
 ef_posterior = prod(PreserveTypeProd(ExponentialFamilyDistribution), ef_prior, ef_likelihood)
ExponentialFamily(Bernoulli)

Or even more concisely:

prod(PreserveTypeProd(ExponentialFamilyDistribution), prior, likelihood)
ExponentialFamily(Bernoulli)

In this example, multiplying two Bernoulli distributions will always result in another Bernoulli distribution. However, this is not the case for all distributions. For instance, the product of two Laplace distributions may not yield another Laplace distribution, and representing the result in the same form might not be possible. In such cases, it's advisable to calculate the result within the exponential family domain. This is because the product of two exponential family distributions can always be represented as another exponential family distribution, as shown here:

prior = Laplace(2.0, 3.0)
 likelihood = Laplace(1.0, 4.0)
 
-prod(PreserveTypeProd(ExponentialFamilyDistribution), prior, likelihood)
ExponentialFamily(Univariate)

Note that the result does not correspond to the Laplace distribution and returns a generic univariate ExponentialFamilyDistribution. This approach ensures consistency and compatibility, especially when dealing with a wide range of probability distributions.

Computing various useful attributes of an exponential family member

The package implements attributes of many well known exponential family members, which are defined in this table. The attributes include getbasemeasure, getsufficientstatistics, getlogpartition, getfisherinformation, and others. In general, the interface for these functions assumes a family member "tag," such as Normal or Bernoulli. Here are some examples of how to use these attributes:

using ExponentialFamily, Distributions
+prod(PreserveTypeProd(ExponentialFamilyDistribution), prior, likelihood)
ExponentialFamily(Univariate)

Note that the result does not correspond to the Laplace distribution and returns a generic univariate ExponentialFamilyDistribution. This approach ensures consistency and compatibility, especially when dealing with a wide range of probability distributions. Refer to the BayesBase for the documentation about available product strategies.

Computing various useful attributes of an exponential family member

The package implements attributes of many well known exponential family members, which are defined in this table. The attributes include getbasemeasure, getsufficientstatistics, getlogpartition, getfisherinformation, and others. In general, the interface for these functions assumes a family member "tag," such as Normal or Bernoulli. Here are some examples of how to use these attributes:

using ExponentialFamily, Distributions
 
 # Returns a function
 basemeasure_of_normal = getbasemeasure(Normal)
@@ -45,4 +45,4 @@
 
 fisherinformation_of_gamma_in_natural_space(gamma_parameters_in_natural_space)
2×2 StaticArraysCore.SMatrix{2, 2, Float64, 4} with indices SOneTo(2)×SOneTo(2):
  1.64493  2.0
- 2.0      4.0

Approximating attributes

Refer to the ExpectationApproximations.jl package for approximating various attributes of the members of the exponential family.

+ 2.0 4.0

Approximating attributes

Refer to the ExpectationApproximations.jl package for approximating various attributes of the members of the exponential family.

diff --git a/dev/index.html b/dev/index.html index b4421c2d..5aafb245 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,2 +1,2 @@ -Home · ExponentialFamily.jl

ExponentialFamily.jl

Julia package that extends the functionality of Distributions.jl by providing a collection of exponential family distributions and customized implementations. It is designed to facilitate working with exponential family distributions and offers specialized functionality tailored to this class of distributions.

Core Principles

The package is built around several core principles:

  • High performance with minimal allocations, striving for complete type stability.
  • Compatibility with distributions defined in Distributions.jl.
  • Ease of use and rich functionality.

Table of Contents

Index

+Home · ExponentialFamily.jl

ExponentialFamily.jl

Julia package that extends the functionality of Distributions.jl by providing a collection of exponential family distributions and customized implementations. It is designed to facilitate working with exponential family distributions and offers specialized functionality tailored to this class of distributions.

Core Principles

The package is built around several core principles:

  • High performance with minimal allocations, striving for complete type stability.
  • Compatibility with distributions defined in Distributions.jl.
  • Ease of use and rich functionality.

Table of Contents

Index

diff --git a/dev/interface/index.html b/dev/interface/index.html index 94a91cbc..7e71510b 100644 --- a/dev/interface/index.html +++ b/dev/interface/index.html @@ -7,29 +7,29 @@ ExponentialFamily(Laplace, conditioned on 1.0) julia> logpdf(ef, 4.0) --6.0

See also: getbasemeasure, getsufficientstatistics, getnaturalparameters, getlogpartition, getsupport

source
ExponentialFamily.ExponentialFamilyDistributionAttributesType
ExponentialFamilyDistributionAttributes(basemeasure, sufficientstatistics, logpartition, support)

A structure to represent the attributes of an exponential family member.

Fields

  • basemeasure::B: The basemeasure of the exponential family member.
  • sufficientstatistics::S: The sufficient statistics of the exponential family member.
  • logpartition::L: The log-partition (cumulant) of the exponential family member.
  • support::P: The support of the exponential family member.

See also: ExponentialFamilyDistribution, getbasemeasure, getsufficientstatistics, getlogpartition, getsupport

source
Distributions.logpdfMethod
logpdf(ef::ExponentialFamilyDistribution, x)

Evaluates and returns the log-density of the exponential family distribution for the input x.

source
Distributions.pdfMethod
pdf(ef::ExponentialFamilyDistribution, x)

Evaluates and returns the probability density function of the exponential family distribution for the input x.

source
Distributions.cdfMethod
cdf(ef::ExponentialFamilyDistribution{D}, x) where { D <: Distribution }

Evaluates and returns the cumulative distribution function of the exponential family distribution for the input x.

source
ExponentialFamily.getnaturalparametersFunction
getnaturalparameters(::ExponentialFamilyDistribution)

Get the natural parameters of the exponential family distribution.

source
ExponentialFamily.getattributesFunction
getattributes(::ExponentialFamilyDistribution)

Returns iether the attributes of the exponential family member or nothing.

See also: ExponentialFamilyDistributionAttributes

source
ExponentialFamily.getconditionerFunction
getconditioner(::ExponentialFamilyDistribution)

Returns either the conditioner of the exponential family distribution or nothing. conditioner is a fixed parameter that is used to ensure that the distribution belongs to the exponential family.

source
ExponentialFamily.isproperFunction
isproper(::ExponentialFamilyDistribution)

Checks if the object of type ExponentialFamilyDistribution is a proper distribution.

source
isproper([ space = NaturalParametersSpace() ], ::Type{T}, parameters, conditioner = nothing) where { T <: Distribution }

A specific verion of isproper defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.

See also: NaturalParametersSpace, MeanParametersSpace

source
ExponentialFamily.getbasemeasureFunction
getbasemeasure(::ExponentialFamilyDistribution)
-getbasemeasure(::Type{ <: Distribution }, [ conditioner ])

Returns the base measure function of the exponential family distribution.

source
ExponentialFamily.getsufficientstatisticsFunction
getsufficientstatistics(::ExponentialFamilyDistribution)
-getsufficientstatistics(::Type{ <: Distribution }, [ conditioner ])

Returns the list of sufficient statistics of the exponential family distribution.

source
ExponentialFamily.getlogpartitionFunction
getlogpartition(::ExponentialFamilyDistribution)
-getlogpartition([ space ], ::Type{ <: Distribution }, [ conditioner ])

Returns the log partition function of the exponential family distribution.

source
ExponentialFamily.getfisherinformationFunction
getfisherinformation(::ExponentialFamilyDistribution)
-getfisherinformation([ space ], ::Type{ <: Distribution }, [ conditioner ])

Returns the function that computes the fisher information matrix of the exponential family distribution.

source
ExponentialFamily.getsupportFunction
getsupport(distribution_or_type)

Returns the support of the exponential family distribution.

source
ExponentialFamily.basemeasureFunction
basemeasure(::ExponentialFamilyDistribution, x)

Returns the computed value of basemeasure of the exponential family distribution at the point x.

See also: getbasemeasure

source
ExponentialFamily.sufficientstatisticsFunction
sufficientstatistics(::ExponentialFamilyDistribution)

Returns the computed values of sufficientstatistics of the exponential family distribution at the point x.

source
ExponentialFamily.logpartitionFunction
logpartition(::ExponentialFamilyDistribution, η)

Return the computed value of logpartition of the exponential family distribution at the point η. By default η = getnaturalparameters(ef).

See also: getlogpartition

source
ExponentialFamily.fisherinformationFunction
fisherinformation(distribution, η)

Return the computed value of fisherinformation of the exponential family distribution at the point η By default η = getnaturalparameters(ef).

See also: getfisherinformation

source
ExponentialFamily.isbasemeasureconstantFunction
isbasemeasureconstant(something)

Returns either NonConstantBaseMeasure() or ConstantBaseMeasure() depending on if the base measure is a constant with respect to the natural parameters of something or not. By default the package assumes that any base measure in a form of the Function is not a constant. It, however, is not true for basemeasure that simply return a constant. In such cases the isbasemeasureconstant must have a specific method.

See also: getbasemeasure, basemeasure

source
ExponentialFamily.ConstantBaseMeasureType

A trait object representing that the base measure is constant.

source
ExponentialFamily.NonConstantBaseMeasureType

A trait object representing that the base measure is not constant.

source

Interfacing with Distributions Defined in the Distributions.jl Package

The Distributions.jl package is a comprehensive library that defines a wide collection of standard distributions. The main objective of the Distributions package is to offer a unified interface for evaluating likelihoods of various distributions, along with convenient sampling routines from these distributions. The ExponentialFamily package provides a lightweight interface for a subset of the distributions defined in the Distributions package.

Conversion between Mean Parameters Space and Natural Parameters Space

The Distributions package introduces the params function, which allows the retrieval of parameters for different distributions. For example:

using Distributions, ExponentialFamily
+-6.0

See also: getbasemeasure, getsufficientstatistics, getnaturalparameters, getlogpartition, getsupport

source
ExponentialFamily.ExponentialFamilyDistributionAttributesType
ExponentialFamilyDistributionAttributes(basemeasure, sufficientstatistics, logpartition, support)

A structure to represent the attributes of an exponential family member.

Fields

  • basemeasure::B: The basemeasure of the exponential family member.
  • sufficientstatistics::S: The sufficient statistics of the exponential family member.
  • logpartition::L: The log-partition (cumulant) of the exponential family member.
  • support::P: The support of the exponential family member.

See also: ExponentialFamilyDistribution, getbasemeasure, getsufficientstatistics, getlogpartition, getsupport

source
Distributions.logpdfMethod
logpdf(ef::ExponentialFamilyDistribution, x)

Evaluates and returns the log-density of the exponential family distribution for the input x.

source
Distributions.pdfMethod
pdf(ef::ExponentialFamilyDistribution, x)

Evaluates and returns the probability density function of the exponential family distribution for the input x.

source
Distributions.cdfMethod
cdf(ef::ExponentialFamilyDistribution{D}, x) where { D <: Distribution }

Evaluates and returns the cumulative distribution function of the exponential family distribution for the input x.

source
ExponentialFamily.getnaturalparametersFunction
getnaturalparameters(::ExponentialFamilyDistribution)

Get the natural parameters of the exponential family distribution.

source
ExponentialFamily.getattributesFunction
getattributes(::ExponentialFamilyDistribution)

Returns iether the attributes of the exponential family member or nothing.

See also: ExponentialFamilyDistributionAttributes

source
ExponentialFamily.getconditionerFunction
getconditioner(::ExponentialFamilyDistribution)

Returns either the conditioner of the exponential family distribution or nothing. conditioner is a fixed parameter that is used to ensure that the distribution belongs to the exponential family.

source
ExponentialFamily.isproperFunction
isproper(::ExponentialFamilyDistribution)

Checks if the object of type ExponentialFamilyDistribution is a proper distribution.

source
isproper([ space = NaturalParametersSpace() ], ::Type{T}, parameters, conditioner = nothing) where { T <: Distribution }

A specific verion of isproper defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.

See also: NaturalParametersSpace, MeanParametersSpace

source
ExponentialFamily.getbasemeasureFunction
getbasemeasure(::ExponentialFamilyDistribution)
+getbasemeasure(::Type{ <: Distribution }, [ conditioner ])

Returns the base measure function of the exponential family distribution.

source
ExponentialFamily.getsufficientstatisticsFunction
getsufficientstatistics(::ExponentialFamilyDistribution)
+getsufficientstatistics(::Type{ <: Distribution }, [ conditioner ])

Returns the list of sufficient statistics of the exponential family distribution.

source
ExponentialFamily.getlogpartitionFunction
getlogpartition(::ExponentialFamilyDistribution)
+getlogpartition([ space ], ::Type{ <: Distribution }, [ conditioner ])

Returns the log partition function of the exponential family distribution.

source
ExponentialFamily.getfisherinformationFunction
getfisherinformation(::ExponentialFamilyDistribution)
+getfisherinformation([ space ], ::Type{ <: Distribution }, [ conditioner ])

Returns the function that computes the fisher information matrix of the exponential family distribution.

source
ExponentialFamily.getsupportFunction
getsupport(distribution_or_type)

Returns the support of the exponential family distribution.

source
ExponentialFamily.basemeasureFunction
basemeasure(::ExponentialFamilyDistribution, x)

Returns the computed value of basemeasure of the exponential family distribution at the point x.

See also: getbasemeasure

source
ExponentialFamily.sufficientstatisticsFunction
sufficientstatistics(::ExponentialFamilyDistribution)

Returns the computed values of sufficientstatistics of the exponential family distribution at the point x.

source
ExponentialFamily.logpartitionFunction
logpartition(::ExponentialFamilyDistribution, η)

Return the computed value of logpartition of the exponential family distribution at the point η. By default η = getnaturalparameters(ef).

See also: getlogpartition

source
ExponentialFamily.fisherinformationFunction
fisherinformation(distribution, η)

Return the computed value of fisherinformation of the exponential family distribution at the point η By default η = getnaturalparameters(ef).

See also: getfisherinformation

source
ExponentialFamily.isbasemeasureconstantFunction
isbasemeasureconstant(something)

Returns either NonConstantBaseMeasure() or ConstantBaseMeasure() depending on if the base measure is a constant with respect to the natural parameters of something or not. By default the package assumes that any base measure in a form of the Function is not a constant. It, however, is not true for basemeasure that simply return a constant. In such cases the isbasemeasureconstant must have a specific method.

See also: getbasemeasure, basemeasure

source
ExponentialFamily.ConstantBaseMeasureType

A trait object representing that the base measure is constant.

source
ExponentialFamily.NonConstantBaseMeasureType

A trait object representing that the base measure is not constant.

source

Interfacing with Distributions Defined in the Distributions.jl Package

The Distributions.jl package is a comprehensive library that defines a wide collection of standard distributions. The main objective of the Distributions package is to offer a unified interface for evaluating likelihoods of various distributions, along with convenient sampling routines from these distributions. The ExponentialFamily package provides a lightweight interface for a subset of the distributions defined in the Distributions package.

Conversion between Mean Parameters Space and Natural Parameters Space

The Distributions package introduces the params function, which allows the retrieval of parameters for different distributions. For example:

using Distributions, ExponentialFamily
 
 distribution = Bernoulli(0.25)
 
-tuple_of_θ = params(distribution)
(0.25,)

These parameters are typically defined in what's known as the mean parameters space. However, the ExponentialFamilyDistribution expects parameters to be in the natural parameters space. To facilitate conversion between these two representations, the ExponentialFamily package provides two structures:

ExponentialFamily.MeanToNaturalType
MeanToNatural(::Type{T})

Return the transformation function that maps the parameters in the mean parameters space to the natural parameters space for a distribution of type T. The transformation function is of signature (params_in_mean_space, [ conditioner ]) -> params_in_natural_space.

See also: NaturalToMean, NaturalParametersSpace, MeanParametersSpace, getmapping

source
ExponentialFamily.NaturalToMeanType
NaturalToMean(::Type{T})

Return the transformation function that maps the parameters in the natural parameters space to the mean parameters space for a distribution of type T. The transformation function is of signature (params_in_natural_space, [ conditioner ]) -> params_in_mean_space.

See also: MeanToNatural, NaturalParametersSpace, MeanParametersSpace, getmapping

source
ExponentialFamily.getmappingFunction
getmapping(::Pair{L, R}, T)

Returns a transformation L -> R between different parametrizations of a distribution of type T.

See also: NaturalParametersSpace, MeanParametersSpace, NaturalToMean, MeanToNatural

source

To convert from the mean parameters space to the corresponding natural parameters space, you can use the following code:

tuple_of_η = MeanToNatural(Bernoulli)(tuple_of_θ)
(-1.0986122886681098,)

And to convert back:

tuple_of_θ = NaturalToMean(Bernoulli)(tuple_of_η)
(0.25,)

Alternatuvely, the following API is supported

map(MeanParametersSpace() => NaturalParametersSpace(), Bernoulli, tuple_of_θ)
(-1.0986122886681098,)
map(NaturalParametersSpace() => MeanParametersSpace(), Bernoulli, tuple_of_η)
(0.25,)

While the ExponentialFamily package employs the respective mappings where needed, it's also possible to call these functions manually. For instance, the generic implementation of the convert function between ExponentialFamilyDistribution and Distribution is built in terms of MeanToNatural and NaturalToMean. Moreover, the convert function performs checks to ensure that the provided parameters and conditioner are suitable for a specific distribution type.

ExponentialFamily.isproperMethod
isproper([ space = NaturalParametersSpace() ], ::Type{T}, parameters, conditioner = nothing) where { T <: Distribution }

A specific verion of isproper defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.

See also: NaturalParametersSpace, MeanParametersSpace

source

Note on the conditioned distributions

For the conditioned distributions, two additional functions separate_conditioner and join_conditioner are used to separate the conditioner and actual parameters returned from the Distributions.params function.

ExponentialFamily.separate_conditionerFunction
separate_conditioner(::Type{T}, params) where {T <: Distribution}

Separates the conditioner argument from params and returns a tuple of (conditioned_params, conditioner). By default returns (params, nothing) but can be overwritten for certain distributions.

julia> (cparams, conditioner) = ExponentialFamily.separate_conditioner(Laplace, (0.0, 1.0))
+tuple_of_θ = params(distribution)
(0.25,)

These parameters are typically defined in what's known as the mean parameters space. However, the ExponentialFamilyDistribution expects parameters to be in the natural parameters space. To facilitate conversion between these two representations, the ExponentialFamily package provides two structures:

To convert from the mean parameters space to the corresponding natural parameters space, you can use the following code:

tuple_of_η = MeanToNatural(Bernoulli)(tuple_of_θ)
(-1.0986122886681098,)

And to convert back:

tuple_of_θ = NaturalToMean(Bernoulli)(tuple_of_η)
(0.25,)

Alternatuvely, the following API is supported

map(MeanParametersSpace() => NaturalParametersSpace(), Bernoulli, tuple_of_θ)
(-1.0986122886681098,)
map(NaturalParametersSpace() => MeanParametersSpace(), Bernoulli, tuple_of_η)
(0.25,)

While the ExponentialFamily package employs the respective mappings where needed, it's also possible to call these functions manually. For instance, the generic implementation of the convert function between ExponentialFamilyDistribution and Distribution is built in terms of MeanToNatural and NaturalToMean. Moreover, the convert function performs checks to ensure that the provided parameters and conditioner are suitable for a specific distribution type.

ExponentialFamily.isproperMethod
isproper([ space = NaturalParametersSpace() ], ::Type{T}, parameters, conditioner = nothing) where { T <: Distribution }

A specific verion of isproper defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.

See also: NaturalParametersSpace, MeanParametersSpace

source

Note on the conditioned distributions

For the conditioned distributions, two additional functions separate_conditioner and join_conditioner are used to separate the conditioner and actual parameters returned from the Distributions.params function.

ExponentialFamily.separate_conditionerFunction
separate_conditioner(::Type{T}, params) where {T <: Distribution}

Separates the conditioner argument from params and returns a tuple of (conditioned_params, conditioner). By default returns (params, nothing) but can be overwritten for certain distributions.

julia> (cparams, conditioner) = ExponentialFamily.separate_conditioner(Laplace, (0.0, 1.0))
 ((1.0,), 0.0)
 
 julia> params = ExponentialFamily.join_conditioner(Laplace, cparams, conditioner)
 (0.0, 1.0)
 
 julia> Laplace(params...) == Laplace(0.0, 1.0)
-true

See also: ExponentialFamily.join_conditioner

source
ExponentialFamily.join_conditionerFunction
join_conditioner(::Type{T}, params, conditioner) where { T <: Distribution }

Joins the conditioner argument with the params and returns a tuple of joined params, such that it can be used in a constructor of the T distribution.

julia> (cparams, conditioner) = ExponentialFamily.separate_conditioner(Laplace, (0.0, 1.0))
+true

See also: ExponentialFamily.join_conditioner

source
ExponentialFamily.join_conditionerFunction
join_conditioner(::Type{T}, params, conditioner) where { T <: Distribution }

Joins the conditioner argument with the params and returns a tuple of joined params, such that it can be used in a constructor of the T distribution.

julia> (cparams, conditioner) = ExponentialFamily.separate_conditioner(Laplace, (0.0, 1.0))
 ((1.0,), 0.0)
 
 julia> params = ExponentialFamily.join_conditioner(Laplace, cparams, conditioner)
 (0.0, 1.0)
 
 julia> Laplace(params...) == Laplace(0.0, 1.0)
-true

See also: ExponentialFamily.separate_conditioner

source

For example, Laplace distribution defines the functions in the following way

# `params` are coming from the `Distribution.params(::Laplace)` and return (location, scale)
+true

See also: ExponentialFamily.separate_conditioner

source

For example, Laplace distribution defines the functions in the following way

# `params` are coming from the `Distribution.params(::Laplace)` and return (location, scale)
 # The `location`, however is a fixed parameter in the exponential distribution representation of Laplace
 # Hence, we return a tuple of tuple of actual parameter and the conditioner
 function separate_conditioner(::Type{Laplace}, params)
@@ -43,7 +43,7 @@
     (scale, ) = cparams
     location = conditioner
     return (location, scale)
-end

In general, all functions defined for the ExponentialFamilyDistribution, such as getlogpartition or getbasemeasure accept an optional conditioner parameter, which is assumed to be nothing. Conditioned distribution implement the "conditioned" versions of such functions by explicitly requiring the conditioner parameter, e.g.

getsufficientstatistics(Laplace, 1.0) # explicit `conditioner = 1.0`
(ExponentialFamily.var"#344#345"{Float64}(1.0),)

Efficient packing of the natural parameters into a vectorized form

The ExponentialFamilyDistribution type stores its natural parameters in a vectorized, or packed, format. This is done for the sake of efficiency and to enhance compatibility with autodiff packages like ForwardDiff, which anticipate a single parameter vector. As a result, the tuple of natural parameters needs to be converted to its corresponding vectorized form and vice versa. To achieve this, the package provides the flatten_parameters, pack_parameters and unpack_parameters functions.

ExponentialFamily.flatten_parametersFunction
flatten_parameters(::Type{T}, params::Tuple)

This function returns the parameters of a distribution of type T in a flattened form without actually allocating the container.

source
ExponentialFamily.pack_parametersFunction
pack_parameters([ space ], ::Type{T}, params::Tuple)

This function returns the parameters of a distribution of type T in a vectorized (packed) form. For most of the distributions the packed versions are of the same structure in any parameters space. For some distributions, however, it is necessary to indicate the space of the packaged parameters.

julia> ExponentialFamily.pack_parameters((1, [2.0, 3.0], [4.0 5.0 6.0; 7.0 8.0 9.0]))
+end

In general, all functions defined for the ExponentialFamilyDistribution, such as getlogpartition or getbasemeasure accept an optional conditioner parameter, which is assumed to be nothing. Conditioned distribution implement the "conditioned" versions of such functions by explicitly requiring the conditioner parameter, e.g.

getsufficientstatistics(Laplace, 1.0) # explicit `conditioner = 1.0`
(ExponentialFamily.var"#340#341"{Float64}(1.0),)

Efficient packing of the natural parameters into a vectorized form

The ExponentialFamilyDistribution type stores its natural parameters in a vectorized, or packed, format. This is done for the sake of efficiency and to enhance compatibility with autodiff packages like ForwardDiff, which anticipate a single parameter vector. As a result, the tuple of natural parameters needs to be converted to its corresponding vectorized form and vice versa. To achieve this, the package provides the flatten_parameters, pack_parameters and unpack_parameters functions.

ExponentialFamily.flatten_parametersFunction
flatten_parameters(::Type{T}, params::Tuple)

This function returns the parameters of a distribution of type T in a flattened form without actually allocating the container.

source
ExponentialFamily.pack_parametersFunction
pack_parameters([ space ], ::Type{T}, params::Tuple)

This function returns the parameters of a distribution of type T in a vectorized (packed) form. For most of the distributions the packed versions are of the same structure in any parameters space. For some distributions, however, it is necessary to indicate the space of the packaged parameters.

julia> ExponentialFamily.pack_parameters((1, [2.0, 3.0], [4.0 5.0 6.0; 7.0 8.0 9.0]))
 9-element Vector{Float64}:
  1.0
  2.0
@@ -53,6 +53,6 @@
  5.0
  8.0
  6.0
- 9.0
source
ExponentialFamily.unpack_parametersFunction
unpack_parameters([ space ], ::Type{T}, parameters)

This function "unpack" the vectorized form of the parameters in a tuple. For most of the distributions the packed parameters are of the same structure in any parameters space. For some distributions, however, it is necessary to indicate the space of the packaged parameters.

See also: MeanParametersSpace, NaturalParametersSpace

source

These functions are not exported by default, but it's important to note that the ExponentialFamilyDistributions type doesn't actually store the parameter tuple internally. Instead, the getnaturalparameters function returns the corresponding vectorized (packed) form of the natural parameters. In general, only the ExponentialFamily.unpack_parameters function must be implemented, as others could be implemented in a generic way.

Attributes of the exponential family distribution based on Distribution

The ExponentialFamilyDistribution{T} where { T <: Distribution } type encompasses all fundamental attributes of the exponential family, including basemeasure, logpartition, sufficientstatistics, and fisherinformation. Furthermore, it's possible to retrieve the actual functions that compute these attributes. For instance, consider the following example:

basemeasure_of_bernoilli = getbasemeasure(Bernoulli)
+ 9.0
source
ExponentialFamily.unpack_parametersFunction
unpack_parameters([ space ], ::Type{T}, parameters)

This function "unpack" the vectorized form of the parameters in a tuple. For most of the distributions the packed parameters are of the same structure in any parameters space. For some distributions, however, it is necessary to indicate the space of the packaged parameters.

See also: MeanParametersSpace, NaturalParametersSpace

source

These functions are not exported by default, but it's important to note that the ExponentialFamilyDistributions type doesn't actually store the parameter tuple internally. Instead, the getnaturalparameters function returns the corresponding vectorized (packed) form of the natural parameters. In general, only the ExponentialFamily.unpack_parameters function must be implemented, as others could be implemented in a generic way.

Attributes of the exponential family distribution based on Distribution

The ExponentialFamilyDistribution{T} where { T <: Distribution } type encompasses all fundamental attributes of the exponential family, including basemeasure, logpartition, sufficientstatistics, and fisherinformation. Furthermore, it's possible to retrieve the actual functions that compute these attributes. For instance, consider the following example:

basemeasure_of_bernoilli = getbasemeasure(Bernoulli)
 
-basemeasure_of_bernoilli(0)
1
ExponentialFamily.isproperMethod
isproper([ space = NaturalParametersSpace() ], ::Type{T}, parameters, conditioner = nothing) where { T <: Distribution }

A specific verion of isproper defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.

See also: NaturalParametersSpace, MeanParametersSpace

source
ExponentialFamily.getbasemeasureMethod
getbasemeasure(::Type{<:Distribution}, [ conditioner ])

A specific verion of getbasemeasure defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. For conditional exponential family distributions requires an extra conditioner argument.

source
ExponentialFamily.getsufficientstatisticsMethod
getsufficientstatistics(::Type{<:Distribution}, [ conditioner ])

A specific verion of getsufficientstatistics defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. For conditional exponential family distributions requires an extra conditioner argument.

source
ExponentialFamily.getlogpartitionMethod
getlogpartition([ space = NaturalParametersSpace() ], ::Type{T}, [ conditioner ]) where { T <: Distribution }

A specific verion of getlogpartition defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.

See also: NaturalParametersSpace, MeanParametersSpace

source
ExponentialFamily.getfisherinformationMethod
getfisherinformation([ space = NaturalParametersSpace() ], ::Type{T}) where { T <: Distribution }

A specific verion of getfisherinformation defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.

See also: NaturalParametersSpace, MeanParametersSpace

source

Certain functions require knowledge about which parameter space is being used. By default, the NaturalParametersSpace is assumed.

getlogpartition(Bernoulli) === getlogpartition(NaturalParametersSpace(), Bernoulli)
true
ExponentialFamily.NaturalParametersSpaceType
NaturalParametersSpace

Specifies the natural parameters space η as the desired parameters space. Some functions (such as logpartition or fisherinformation) accept an additional space parameter to disambiguate the desired parameters space. Use map(NaturalParametersSpace() => MeanParametersSpace(), T, parameters, conditioner) to map the parameters and the conditioner of a distribution of type T from the natural parametrization to the corresponding mean parametrization.

See also: MeanParametersSpace, getmapping, NaturalToMean, MeanToNatural

source
ExponentialFamily.MeanParametersSpaceType
MeanParametersSpace

Specifies the mean parameters space θ as the desired parameters space. Some functions (such as logpartition or fisherinformation) accept an additional space parameter to disambiguate the desired parameters space. Use map(MeanParametersSpace() => NaturalParametersSpace(), T, parameters, conditioner) to map the parameters and the conditioner of a distribution of type T from the mean parametrization to the corresponding natural parametrization.

See also: NaturalParametersSpace, getmapping, NaturalToMean, MeanToNatural

source

The isbasemeasureconstant function is defined for all supported distributions as well.

isbasemeasureconstant(Bernoulli)
ConstantBaseMeasure()

Extra defined distributions

The package defines a list of extra distributions for a purpose of more efficiency in different circumstances. The list is available here.

+basemeasure_of_bernoilli(0)
1
ExponentialFamily.isproperMethod
isproper([ space = NaturalParametersSpace() ], ::Type{T}, parameters, conditioner = nothing) where { T <: Distribution }

A specific verion of isproper defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.

See also: NaturalParametersSpace, MeanParametersSpace

source
ExponentialFamily.getbasemeasureMethod
getbasemeasure(::Type{<:Distribution}, [ conditioner ])

A specific verion of getbasemeasure defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. For conditional exponential family distributions requires an extra conditioner argument.

source
ExponentialFamily.getsufficientstatisticsMethod
getsufficientstatistics(::Type{<:Distribution}, [ conditioner ])

A specific verion of getsufficientstatistics defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. For conditional exponential family distributions requires an extra conditioner argument.

source
ExponentialFamily.getlogpartitionMethod
getlogpartition([ space = NaturalParametersSpace() ], ::Type{T}, [ conditioner ]) where { T <: Distribution }

A specific verion of getlogpartition defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.

See also: NaturalParametersSpace, MeanParametersSpace

source
ExponentialFamily.getfisherinformationMethod
getfisherinformation([ space = NaturalParametersSpace() ], ::Type{T}) where { T <: Distribution }

A specific verion of getfisherinformation defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.

See also: NaturalParametersSpace, MeanParametersSpace

source

Certain functions require knowledge about which parameter space is being used. By default, the NaturalParametersSpace is assumed.

getlogpartition(Bernoulli) === getlogpartition(NaturalParametersSpace(), Bernoulli)
true
ExponentialFamily.NaturalParametersSpaceType
NaturalParametersSpace

Specifies the natural parameters space η as the desired parameters space. Some functions (such as logpartition or fisherinformation) accept an additional space parameter to disambiguate the desired parameters space. Use map(NaturalParametersSpace() => MeanParametersSpace(), T, parameters, conditioner) to map the parameters and the conditioner of a distribution of type T from the natural parametrization to the corresponding mean parametrization.

See also: MeanParametersSpace, getmapping, NaturalToMean, MeanToNatural

source
ExponentialFamily.MeanParametersSpaceType
MeanParametersSpace

Specifies the mean parameters space θ as the desired parameters space. Some functions (such as logpartition or fisherinformation) accept an additional space parameter to disambiguate the desired parameters space. Use map(MeanParametersSpace() => NaturalParametersSpace(), T, parameters, conditioner) to map the parameters and the conditioner of a distribution of type T from the mean parametrization to the corresponding natural parametrization.

See also: NaturalParametersSpace, getmapping, NaturalToMean, MeanToNatural

source

The isbasemeasureconstant function is defined for all supported distributions as well.

isbasemeasureconstant(Bernoulli)
ConstantBaseMeasure()

Extra defined distributions

The package defines a list of extra distributions for a purpose of more efficiency in different circumstances. The list is available here.

diff --git a/dev/library/index.html b/dev/library/index.html index 6f24e762..81599c95 100644 --- a/dev/library/index.html +++ b/dev/library/index.html @@ -1,44 +1,2 @@ -Library · ExponentialFamily.jl

Library API

Product API

One of the central functions in this package is the ability to calculate the product of two distributions over the same variable. You can also refer to the corresponding example for practical usage.

The prod function is a key feature of this package. It accepts a strategy as its first argument, which defines how the prod function should behave and what results you can expect.

Base.prodMethod
prod(strategy, left, right)

prod function is used to find a product of two probability distributions (or any other objects) over same variable (e.g. 𝓝(x|μ1, σ1) × 𝓝(x|μ2, σ2)). There are multiple strategies for prod function, e.g. ClosedProd, GenericProd or PreserveTypeProd.

Examples:

julia> product = prod(PreserveTypeProd(Distribution), NormalMeanVariance(-1.0, 1.0), NormalMeanVariance(1.0, 1.0))
-NormalWeightedMeanPrecision{Float64}(xi=0.0, w=2.0)
-
-julia> mean(product), var(product)
-(0.0, 0.5)
julia> product = prod(PreserveTypeProd(NormalMeanVariance), NormalMeanVariance(-1.0, 1.0), NormalMeanVariance(1.0, 1.0))
-NormalMeanVariance{Float64}(μ=0.0, v=0.5)
-
-julia> mean(product), var(product)
-(0.0, 0.5)
julia> product = prod(PreserveTypeProd(ExponentialFamilyDistribution), NormalMeanVariance(-1.0, 1.0), NormalMeanVariance(1.0, 1.0))
-ExponentialFamily(NormalMeanVariance)
-
-julia> mean(product), var(product)
-(0.0, 0.5)

See also: default_prod_rule, ClosedProd, PreserveTypeProd, GenericProd

source

Product strategies

For certain distributions, it's possible to compute the product using a straightforward mathematical equation, yielding a closed-form solution. However, for some distributions, finding a closed-form solution might not be feasible. Various strategies ensure consistent behavior in these situations. These strategies can either guarantee a fast and closed-form solution or, when necessary, fall back to a slower but more generic method.

ExponentialFamily.ClosedProdType
ClosedProd

ClosedProd is one of the strategies for prod function. This strategy uses either PreserveTypeProd(Distribution) or PreserveTypeProd(ExponentialFamilyDistribution), depending on the types of the input arguments. For example, if both inputs are of type Distribution, then ClosedProd would fallback to PreserveTypeProd(Distribution).

See also: prod, PreserveTypeProd, GenericProd

source
ExponentialFamily.PreserveTypeProdType
PreserveTypeProd{T}

PreserveTypeProd is one of the strategies for prod function. This strategy constraint an output of a prod to be in some specific form. By default it uses the strategy from default_prod_rule and converts the output to the prespecified type but can be overwritten for some distributions for better performance.

julia> product = prod(PreserveTypeProd(NormalMeanVariance), NormalMeanVariance(-1.0, 1.0), NormalMeanVariance(1.0, 1.0))
-NormalMeanVariance{Float64}(μ=0.0, v=0.5)
-
-julia> mean(product), var(product)
-(0.0, 0.5)

See also: prod, ClosedProd, PreserveTypeLeftProd, PreserveTypeRightProd, GenericProd

source
ExponentialFamily.GenericProdType
GenericProd

GenericProd is one of the strategies for prod function. This strategy does always produces a result, even if the closed form product is not availble, in which case simply returns the ProductOf object. GenericProd sometimes fallbacks to the default_prod_rule which it may or may not use under some circumstances. For example if the default_prod_rule is ClosedProd - GenericProd will try to optimize the tree with analytical closed solutions (if possible).

See also: prod, ProductOf, ClosedProd, PreserveTypeProd, default_prod_rule

source
ExponentialFamily.ProductOfType
ProductOf

A generic structure representing a product of two distributions. Can be viewed as a tuple of (left, right). Does not check nor supports neither variate forms during the creation stage. Uses the fuse_support function to fuse supports of two different distributions.

This object does not define any statistical properties (such as mean or var etc) and cannot be used as a distribution explicitly. Instead, it must be further approximated as a member of some other distribution.

See also: prod, GenericProd, ExponentialFamily.fuse_supports

source
ExponentialFamily.LinearizedProductOfType
LinearizedProductOf

An efficient linearized implementation of product of multiple distributions. This structure prevents ProductOf tree from growing too much in case of identical objects. This trick significantly reduces Julia compilation times when closed product rules are not available but distributions are of the same type. Essentially this structure linearizes leaves of the ProductOf tree in case if it sees objects of the same type (via dispatch).

See also: ProductOf, [GenericProd]

source

These strategies offer flexibility and reliability when working with different types of distributions, ensuring that the package can handle a wide range of cases effectively.

Additional distributions

These are the distributions that are not included in the Distributions.jl package.

ExponentialFamily.MatrixDirichletType
MatrixDirichlet{T <: Real, A <: AbstractMatrix{T}} <: ContinuousMatrixDistribution

A matrix-valued MatrixDirichlet distribution, where T is the element type of the matrix A. The a field stores the matrix parameter of the distribution.

Fields

  • a::A: The matrix parameter of the MatrixDirichlet distribution.
source
ExponentialFamily.GammaShapeRateType
GammaShapeRate{T <: Real}

A univariate gamma distribution parametrized by its shape a and rate b.

Fields

  • a: The shape parameter of the gamma distribution. It should be a positive real number.
  • b: The rate parameter of the gamma distribution. It should be a positive real number.
source
ExponentialFamily.GammaShapeScaleType
GammaShapeScale{T}

A continuous univariate gamma distribution parametrized by its shape α and scale β parameters.

Fields

  • α: The shape parameter of the gamma distribution. It should be a positive real number.
  • β: The scale parameter of the gamma distribution. It should be a positive real number.

Note

  • GammaShapeScale is an alias for Gamma from Distributions.jl.
source
ExponentialFamily.NormalMeanPrecisionType
NormalMeanPrecision{T <: Real} <: ContinuousUnivariateDistribution

A normal distribution with a known mean μ and precision w.

Fields

  • μ::T: The mean of the normal distribution.
  • w::T: The precision of the normal distribution.
source
ExponentialFamily.NormalMeanVarianceType
NormalMeanVariance{T <: Real} <: ContinuousUnivariateDistribution

A normal distribution with a known mean μ and variance v.

Fields

  • μ::T: The mean of the normal distribution.
  • v::T: The variance of the normal distribution.
source
ExponentialFamily.NormalWeightedMeanPrecisionType
NormalWeightedMeanPrecision{T <: Real} <: ContinuousUnivariateDistribution

A normal distribution parametrized by its natural parameters: the weighted mean xi and precision w.

Fields

  • xi::T: The weighted mean of the normal distribution. xi is computed as w * μ, where μ is the mean of the distribution.
  • w::T: The precision (inverse variance) of the normal distribution.
source
ExponentialFamily.MvNormalMeanPrecisionType
MvNormalMeanPrecision{T <: Real, M <: AbstractVector{T}, P <: AbstractMatrix{T}} <: AbstractMvNormal

A multivariate normal distribution with mean μ and precision matrix Λ, where T is the element type of the vectors M and matrices P.

Fields

  • μ::M: The mean vector of the multivariate normal distribution.
  • Λ::P: The precision matrix (inverse of the covariance matrix) of the multivariate normal distribution.
source
ExponentialFamily.MvNormalMeanCovarianceType
MvNormalMeanCovariance{T <: Real, M <: AbstractVector{T}, P <: AbstractMatrix{T}} <: AbstractMvNormal

A multivariate normal distribution with mean μ and covariance matrix Σ, where T is the element type of the vectors M and matrices P.

Fields

  • μ::M: The mean vector of the multivariate normal distribution.
  • Σ::P: The covariance matrix of the multivariate normal distribution
source
ExponentialFamily.MvNormalWeightedMeanPrecisionType
MvNormalWeightedMeanPrecision{T <: Real, M <: AbstractVector{T}, P <: AbstractMatrix{T}} <: AbstractMvNormal

A multivariate normal distribution with a weighted mean vector xi and precision matrix Λ, where T is the element type of the vectors M and matrices P. This struct represents a natural parametrization of a multivariate Gaussian distribution.

Fields

  • xi::M: The weighted mean vector of the multivariate normal distribution.
  • Λ::P: The precision matrix (inverse of the covariance matrix) of the multivariate normal distribution.
source
ExponentialFamily.JointNormalType
JointNormal{D, S}

JointNormal is an auxilary structure used for the joint marginal over Normally distributed variables. JointNormal stores a vector with the original dimensionalities (ds), so statistics can later be re-separated.

Use ExponentialFamily.getcomponent(joint, index) to get a specific component of the joint distribution.

Fields

  • dist: joint distribution (typically just a big MvNormal distribution, but maybe a tuple of individual means and covariance matrices)
  • ds: a tuple with the original dimensionalities of individual Normal distributions
  • ds[k] = (n,) where n is an integer indicates Multivariate normal of size n
  • ds[k] = () indicates Univariate normal
source
ExponentialFamily.WishartFastType
WishartFast{T <: Real, A <: AbstractMatrix{T}} <: ContinuousMatrixDistribution

The WishartFast struct represents a fast version of the Wishart distribution. It is similar to the Wishart distribution from Distributions.jl, but it does not check input arguments, allowing the creation of improper Wishart messages.

For model creation and regular usage, it is recommended to use Wishart from Distributions.jl. The WishartFast distribution is intended for internal purposes and should not be directly used by regular users.

Fields

  • ν::T: The degrees of freedom parameter of the Wishart distribution.
  • invS::A: The inverse scale matrix parameter of the Wishart distribution.

Note

Internally, WishartFast stores and creates the inverse of its scale matrix. However, the params() function returns the scale matrix itself for backward compatibility. This is done to ensure better stability in the message passing update rules for ReactiveMP.jl.

source
ExponentialFamily.InverseWishartFastType
InverseWishartFast{T <: Real, A <: AbstractMatrix{T}} <: ContinuousMatrixDistribution

The InverseWishartFast struct represents an improper Inverse Wishart distribution. It is similar to the InverseWishart distribution from Distributions.jl, but it does not check input arguments, allowing the creation of improper InverseWishart messages.

For model creation and regular usage, it is recommended to use InverseWishart from Distributions.jl. The InverseWishartFast distribution is intended for internal purposes and should not be directly used by regular users.

Fields

  • ν::T: The degrees of freedom parameter of the inverse Wishart distribution.
  • S::A: The scale matrix parameter of the inverse Wishart distribution.

Note

The InverseWishartFast distribution does not enforce input argument validation, making it suitable for specialized cases where improper message constructions are needed.

source
ExponentialFamily.NormalGammaType
NormalGamma{T <: Real} <: ContinuousMultivariateDistribution

A normal-gamma distribution, where T is a real number. This distribution is a joint distribution of a normal random variable with mean μ and precision λ, and a gamma-distributed random variable with shape α and rate β.

Fields

  • μ::T: The mean of the normal distribution.
  • λ::T: The precision of the normal distribution.
  • α::T: The shape parameter of the gamma distribution.
  • β::T: The rate parameter of the gamma distribution.
source
ExponentialFamily.MvNormalWishartType
MvNormalWishart{T, M <: AbstractArray{T}, V <: AbstractMatrix{T}, K <: Real, N <: Real} <: ContinuousMatrixDistribution

A multivariate normal-Wishart distribution, where T is the element type of the arrays M and matrices V, and K and N are real numbers. This distribution is a joint distribution of a multivariate normal random variable with mean μ and a Wishart-distributed random matrix with scale matrix Ψ, degrees of freedom ν, and the scalar κ as a scaling parameter.

Fields

  • μ::M: The mean vector of the multivariate normal distribution.
  • Ψ::V: The scale matrix of the Wishart distribution.
  • κ::K: The scaling parameter of the Wishart distribution.
  • ν::N: The degrees of freedom of the Wishart distribution
source
ExponentialFamily.FactorizedJointType
FactorizedJoint

FactorizedJoint represents a joint distribution of independent random variables. Use getindex() function or square-brackets indexing to access the marginal distribution for individual variables.

source

Promotion type utilities

Extra stats functions

ExponentialFamily.logmvbetaFunction
logmvbeta(x)

Uses the numerically stable algorithm to compute the logarithm of the multivariate beta distribution over with the parameter vector x.

source
ExponentialFamily.clamplogFunction
clamplog(x)

Same as log but clamps the input argument x to be in the range tiny <= x <= typemax(x) such that log(0) does not explode.

source

Helper utilities

ExponentialFamily.vagueFunction
vague(distribution_type, [ dims... ])

vague function returns uninformative probability distribution of a given type.

source
ExponentialFamily.logpdf_sample_optimizedFunction
logpdf_sample_optimized(distribution)

logpdf_sample_optimized function takes as an input a distribution and returns corresponding optimized two versions for taking logpdf() and sampling with rand! respectively. By default returns the same distribution, but some distributions may override default behaviour for better efficiency.

Example

julia> d = vague(MvNormalMeanPrecision, 2)
-MvNormalMeanPrecision(
-μ: [0.0, 0.0]
-Λ: [1.0e-12 0.0; 0.0 1.0e-12]
-)
-
-
-julia> ExponentialFamily.logpdf_sample_optimized(d)
-(FullNormal(
-dim: 2
-μ: [0.0, 0.0]
-Σ: [1.0e12 -0.0; -0.0 1.0e12]
-)
-, FullNormal(
-dim: 2
-μ: [0.0, 0.0]
-Σ: [1.0e12 -0.0; -0.0 1.0e12]
-)
-)
source
ExponentialFamily.fuse_supportsFunction
fuse_supports(left, right)

Fuse supports of two distributions of left and right. By default, checks that the supports are identical and throws an error otherwise. Can implement specific fusions for specific distributions.

See also: prod, ProductOf

source
+Library · ExponentialFamily.jl

Library API

Additional distributions

These are the distributions that are not included in the Distributions.jl package.

ExponentialFamily.MatrixDirichletType
MatrixDirichlet{T <: Real, A <: AbstractMatrix{T}} <: ContinuousMatrixDistribution

A matrix-valued MatrixDirichlet distribution, where T is the element type of the matrix A. The a field stores the matrix parameter of the distribution.

Fields

  • a::A: The matrix parameter of the MatrixDirichlet distribution.
source
ExponentialFamily.GammaShapeRateType
GammaShapeRate{T <: Real}

A univariate gamma distribution parametrized by its shape a and rate b.

Fields

  • a: The shape parameter of the gamma distribution. It should be a positive real number.
  • b: The rate parameter of the gamma distribution. It should be a positive real number.
source
ExponentialFamily.GammaShapeScaleType
GammaShapeScale{T}

A continuous univariate gamma distribution parametrized by its shape α and scale β parameters.

Fields

  • α: The shape parameter of the gamma distribution. It should be a positive real number.
  • β: The scale parameter of the gamma distribution. It should be a positive real number.

Note

  • GammaShapeScale is an alias for Gamma from Distributions.jl.
source
ExponentialFamily.NormalMeanPrecisionType
NormalMeanPrecision{T <: Real} <: ContinuousUnivariateDistribution

A normal distribution with a known mean μ and precision w.

Fields

  • μ::T: The mean of the normal distribution.
  • w::T: The precision of the normal distribution.
source
ExponentialFamily.NormalMeanVarianceType
NormalMeanVariance{T <: Real} <: ContinuousUnivariateDistribution

A normal distribution with a known mean μ and variance v.

Fields

  • μ::T: The mean of the normal distribution.
  • v::T: The variance of the normal distribution.
source
ExponentialFamily.NormalWeightedMeanPrecisionType
NormalWeightedMeanPrecision{T <: Real} <: ContinuousUnivariateDistribution

A normal distribution parametrized by its natural parameters: the weighted mean xi and precision w.

Fields

  • xi::T: The weighted mean of the normal distribution. xi is computed as w * μ, where μ is the mean of the distribution.
  • w::T: The precision (inverse variance) of the normal distribution.
source
ExponentialFamily.MvNormalMeanPrecisionType
MvNormalMeanPrecision{T <: Real, M <: AbstractVector{T}, P <: AbstractMatrix{T}} <: AbstractMvNormal

A multivariate normal distribution with mean μ and precision matrix Λ, where T is the element type of the vectors M and matrices P.

Fields

  • μ::M: The mean vector of the multivariate normal distribution.
  • Λ::P: The precision matrix (inverse of the covariance matrix) of the multivariate normal distribution.
source
ExponentialFamily.MvNormalMeanCovarianceType
MvNormalMeanCovariance{T <: Real, M <: AbstractVector{T}, P <: AbstractMatrix{T}} <: AbstractMvNormal

A multivariate normal distribution with mean μ and covariance matrix Σ, where T is the element type of the vectors M and matrices P.

Fields

  • μ::M: The mean vector of the multivariate normal distribution.
  • Σ::P: The covariance matrix of the multivariate normal distribution
source
ExponentialFamily.MvNormalWeightedMeanPrecisionType
MvNormalWeightedMeanPrecision{T <: Real, M <: AbstractVector{T}, P <: AbstractMatrix{T}} <: AbstractMvNormal

A multivariate normal distribution with a weighted mean vector xi and precision matrix Λ, where T is the element type of the vectors M and matrices P. This struct represents a natural parametrization of a multivariate Gaussian distribution.

Fields

  • xi::M: The weighted mean vector of the multivariate normal distribution.
  • Λ::P: The precision matrix (inverse of the covariance matrix) of the multivariate normal distribution.
source
ExponentialFamily.JointNormalType
JointNormal{D, S}

JointNormal is an auxilary structure used for the joint marginal over Normally distributed variables. JointNormal stores a vector with the original dimensionalities (ds), so statistics can later be re-separated.

Use ExponentialFamily.getcomponent(joint, index) to get a specific component of the joint distribution.

Fields

  • dist: joint distribution (typically just a big MvNormal distribution, but maybe a tuple of individual means and covariance matrices)
  • ds: a tuple with the original dimensionalities of individual Normal distributions
  • ds[k] = (n,) where n is an integer indicates Multivariate normal of size n
  • ds[k] = () indicates Univariate normal
source
ExponentialFamily.WishartFastType
WishartFast{T <: Real, A <: AbstractMatrix{T}} <: ContinuousMatrixDistribution

The WishartFast struct represents a fast version of the Wishart distribution. It is similar to the Wishart distribution from Distributions.jl, but it does not check input arguments, allowing the creation of improper Wishart messages.

For model creation and regular usage, it is recommended to use Wishart from Distributions.jl. The WishartFast distribution is intended for internal purposes and should not be directly used by regular users.

Fields

  • ν::T: The degrees of freedom parameter of the Wishart distribution.
  • invS::A: The inverse scale matrix parameter of the Wishart distribution.

Note

Internally, WishartFast stores and creates the inverse of its scale matrix. However, the params() function returns the scale matrix itself for backward compatibility. This is done to ensure better stability in the message passing update rules for ReactiveMP.jl.

source
ExponentialFamily.InverseWishartFastType
InverseWishartFast{T <: Real, A <: AbstractMatrix{T}} <: ContinuousMatrixDistribution

The InverseWishartFast struct represents an improper Inverse Wishart distribution. It is similar to the InverseWishart distribution from Distributions.jl, but it does not check input arguments, allowing the creation of improper InverseWishart messages.

For model creation and regular usage, it is recommended to use InverseWishart from Distributions.jl. The InverseWishartFast distribution is intended for internal purposes and should not be directly used by regular users.

Fields

  • ν::T: The degrees of freedom parameter of the inverse Wishart distribution.
  • S::A: The scale matrix parameter of the inverse Wishart distribution.

Note

The InverseWishartFast distribution does not enforce input argument validation, making it suitable for specialized cases where improper message constructions are needed.

source
ExponentialFamily.NormalGammaType
NormalGamma{T <: Real} <: ContinuousMultivariateDistribution

A normal-gamma distribution, where T is a real number. This distribution is a joint distribution of a normal random variable with mean μ and precision λ, and a gamma-distributed random variable with shape α and rate β.

Fields

  • μ::T: The mean of the normal distribution.
  • λ::T: The precision of the normal distribution.
  • α::T: The shape parameter of the gamma distribution.
  • β::T: The rate parameter of the gamma distribution.
source
ExponentialFamily.MvNormalWishartType
MvNormalWishart{T, M <: AbstractArray{T}, V <: AbstractMatrix{T}, K <: Real, N <: Real} <: ContinuousMatrixDistribution

A multivariate normal-Wishart distribution, where T is the element type of the arrays M and matrices V, and K and N are real numbers. This distribution is a joint distribution of a multivariate normal random variable with mean μ and a Wishart-distributed random matrix with scale matrix Ψ, degrees of freedom ν, and the scalar κ as a scaling parameter.

Fields

  • μ::M: The mean vector of the multivariate normal distribution.
  • Ψ::V: The scale matrix of the Wishart distribution.
  • κ::K: The scaling parameter of the Wishart distribution.
  • ν::N: The degrees of freedom of the Wishart distribution
source
diff --git a/dev/search_index.js b/dev/search_index.js index 340a3018..46686a7a 100644 --- a/dev/search_index.js +++ b/dev/search_index.js @@ -1,3 +1,3 @@ var documenterSearchIndex = {"docs": -[{"location":"interface/#interface","page":"Interface","title":"The ExponentialFamilyDistribution Interface","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"This page describes the philosophy and design concepts behind the ExponentialFamilyDistribution interface. In a nutshell, the primary purpose of the ExponentialFamily package is to provide a generic interface for an ExponentialFamilyDistribution. It is beneficial to become familiar with the Wikipedia article on the exponential family before delving into the implementation details of this package.","category":"page"},{"location":"interface/#Notation","page":"Interface","title":"Notation","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"In the context of the package, exponential family distributions are represented in the form:","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"f_X(xmideta) = h(x) cdot expleft eta cdot T(x) - A(eta) right","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"Here:","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"h(x) is the base measure.\nT(x) represents sufficient statistics.\nA(η) stands for the log partition.\nη denotes the natural parameters.","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"In the following discussion we also use the following convention","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"η corresponds to the distribution's natural parameters in the natural parameter space.\nθ corresponds to the distribution's mean parameters in the mean parameter space.","category":"page"},{"location":"interface/#ExponentialFamilyDistribution-structure","page":"Interface","title":"ExponentialFamilyDistribution structure","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"ExponentialFamilyDistribution\nExponentialFamilyDistributionAttributes\nlogpdf(ef::ExponentialFamilyDistribution, x)\npdf(ef::ExponentialFamilyDistribution, x)\ncdf(ef::ExponentialFamilyDistribution{D}, x) where {D <: Distribution}\ngetnaturalparameters\ngetattributes\ngetconditioner\nisproper\ngetbasemeasure\ngetsufficientstatistics\ngetlogpartition\ngetfisherinformation\ngetsupport\nbasemeasure\nsufficientstatistics\nlogpartition\nfisherinformation\nisbasemeasureconstant\nConstantBaseMeasure\nNonConstantBaseMeasure","category":"page"},{"location":"interface/#ExponentialFamily.ExponentialFamilyDistribution","page":"Interface","title":"ExponentialFamily.ExponentialFamilyDistribution","text":"ExponentialFamilyDistribution(::Type{T}, naturalparameters, conditioner, attributes)\n\nExponentialFamilyDistribution structure represents a generic exponential family distribution in natural parameterization. Type T can be either a distribution type (e.g. from the Distributions.jl package) or a variate type (e.g. Univariate). In the context of the package, exponential family distributions are represented in the form:\n\npₓ(x η) = h(x) exp η T(x) - A(η) \n\nHere:\n\nh(x) is the base measure.\nT(x) represents sufficient statistics.\nA(η) stands for the log partition.\nη denotes the natural parameters.\n\nFor a given member of exponential family: \n\ngetattributes returns either nothing or ExponentialFamilyDistributionAttributes.\ngetbasemeasure returns a positive a valued function. \ngetsufficientstatistics returns an iterable of functions such as [x, x^2] or [x, logx].\ngetnaturalparameters returns an iterable holding the values of the natural parameters. \ngetlogpartition return a function that depends on the naturalparameters and it ensures that the distribution is normalized to 1. \ngetsupport returns the set that the distribution is defined over. Could be real numbers, positive integers, 3d cube etc. Use ither the ∈ operator or the insupport() function to check if a value belongs to the support.\n\nnote: Note\nThe attributes can be nothing. In which case the package will try to derive the corresponding attributes from the type T.\n\njulia> ef = convert(ExponentialFamilyDistribution, Bernoulli(0.5))\nExponentialFamily(Bernoulli)\n\njulia> getsufficientstatistics(ef)\n(identity,)\n\njulia> ef = convert(ExponentialFamilyDistribution, Laplace(1.0, 0.5))\nExponentialFamily(Laplace, conditioned on 1.0)\n\njulia> logpdf(ef, 4.0)\n-6.0\n\nSee also: getbasemeasure, getsufficientstatistics, getnaturalparameters, getlogpartition, getsupport\n\n\n\n\n\n","category":"type"},{"location":"interface/#ExponentialFamily.ExponentialFamilyDistributionAttributes","page":"Interface","title":"ExponentialFamily.ExponentialFamilyDistributionAttributes","text":"ExponentialFamilyDistributionAttributes(basemeasure, sufficientstatistics, logpartition, support)\n\nA structure to represent the attributes of an exponential family member.\n\nFields\n\nbasemeasure::B: The basemeasure of the exponential family member.\nsufficientstatistics::S: The sufficient statistics of the exponential family member.\nlogpartition::L: The log-partition (cumulant) of the exponential family member.\nsupport::P: The support of the exponential family member.\n\nSee also: ExponentialFamilyDistribution, getbasemeasure, getsufficientstatistics, getlogpartition, getsupport\n\n\n\n\n\n","category":"type"},{"location":"interface/#Distributions.logpdf-Tuple{ExponentialFamilyDistribution, Any}","page":"Interface","title":"Distributions.logpdf","text":"logpdf(ef::ExponentialFamilyDistribution, x)\n\nEvaluates and returns the log-density of the exponential family distribution for the input x.\n\n\n\n\n\n","category":"method"},{"location":"interface/#Distributions.pdf-Tuple{ExponentialFamilyDistribution, Any}","page":"Interface","title":"Distributions.pdf","text":"pdf(ef::ExponentialFamilyDistribution, x)\n\nEvaluates and returns the probability density function of the exponential family distribution for the input x.\n\n\n\n\n\n","category":"method"},{"location":"interface/#Distributions.cdf-Union{Tuple{D}, Tuple{ExponentialFamilyDistribution{D}, Any}} where D<:Distribution","page":"Interface","title":"Distributions.cdf","text":"cdf(ef::ExponentialFamilyDistribution{D}, x) where { D <: Distribution }\n\nEvaluates and returns the cumulative distribution function of the exponential family distribution for the input x.\n\n\n\n\n\n","category":"method"},{"location":"interface/#ExponentialFamily.getnaturalparameters","page":"Interface","title":"ExponentialFamily.getnaturalparameters","text":"getnaturalparameters(::ExponentialFamilyDistribution)\n\nGet the natural parameters of the exponential family distribution.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.getattributes","page":"Interface","title":"ExponentialFamily.getattributes","text":"getattributes(::ExponentialFamilyDistribution)\n\nReturns iether the attributes of the exponential family member or nothing. \n\nSee also: ExponentialFamilyDistributionAttributes\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.getconditioner","page":"Interface","title":"ExponentialFamily.getconditioner","text":"getconditioner(::ExponentialFamilyDistribution)\n\nReturns either the conditioner of the exponential family distribution or nothing. conditioner is a fixed parameter that is used to ensure that the distribution belongs to the exponential family.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.isproper","page":"Interface","title":"ExponentialFamily.isproper","text":"isproper(::ExponentialFamilyDistribution)\n\nChecks if the object of type ExponentialFamilyDistribution is a proper distribution.\n\n\n\n\n\nisproper([ space = NaturalParametersSpace() ], ::Type{T}, parameters, conditioner = nothing) where { T <: Distribution }\n\nA specific verion of isproper defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.\n\nSee also: NaturalParametersSpace, MeanParametersSpace\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.getbasemeasure","page":"Interface","title":"ExponentialFamily.getbasemeasure","text":"getbasemeasure(::ExponentialFamilyDistribution)\ngetbasemeasure(::Type{ <: Distribution }, [ conditioner ])\n\nReturns the base measure function of the exponential family distribution.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.getsufficientstatistics","page":"Interface","title":"ExponentialFamily.getsufficientstatistics","text":"getsufficientstatistics(::ExponentialFamilyDistribution)\ngetsufficientstatistics(::Type{ <: Distribution }, [ conditioner ])\n\nReturns the list of sufficient statistics of the exponential family distribution.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.getlogpartition","page":"Interface","title":"ExponentialFamily.getlogpartition","text":"getlogpartition(::ExponentialFamilyDistribution)\ngetlogpartition([ space ], ::Type{ <: Distribution }, [ conditioner ])\n\nReturns the log partition function of the exponential family distribution.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.getfisherinformation","page":"Interface","title":"ExponentialFamily.getfisherinformation","text":"getfisherinformation(::ExponentialFamilyDistribution)\ngetfisherinformation([ space ], ::Type{ <: Distribution }, [ conditioner ])\n\nReturns the function that computes the fisher information matrix of the exponential family distribution.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.getsupport","page":"Interface","title":"ExponentialFamily.getsupport","text":"getsupport(distribution_or_type)\n\nReturns the support of the exponential family distribution.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.basemeasure","page":"Interface","title":"ExponentialFamily.basemeasure","text":"basemeasure(::ExponentialFamilyDistribution, x)\n\nReturns the computed value of basemeasure of the exponential family distribution at the point x.\n\nSee also: getbasemeasure\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.sufficientstatistics","page":"Interface","title":"ExponentialFamily.sufficientstatistics","text":"sufficientstatistics(::ExponentialFamilyDistribution)\n\nReturns the computed values of sufficientstatistics of the exponential family distribution at the point x.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.logpartition","page":"Interface","title":"ExponentialFamily.logpartition","text":"logpartition(::ExponentialFamilyDistribution, η)\n\nReturn the computed value of logpartition of the exponential family distribution at the point η. By default η = getnaturalparameters(ef).\n\nSee also: getlogpartition\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.fisherinformation","page":"Interface","title":"ExponentialFamily.fisherinformation","text":"fisherinformation(distribution, η)\n\nReturn the computed value of fisherinformation of the exponential family distribution at the point η By default η = getnaturalparameters(ef).\n\nSee also: getfisherinformation\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.isbasemeasureconstant","page":"Interface","title":"ExponentialFamily.isbasemeasureconstant","text":"isbasemeasureconstant(something)\n\nReturns either NonConstantBaseMeasure() or ConstantBaseMeasure() depending on if the base measure is a constant with respect to the natural parameters of something or not. By default the package assumes that any base measure in a form of the Function is not a constant. It, however, is not true for basemeasure that simply return a constant. In such cases the isbasemeasureconstant must have a specific method.\n\nSee also: getbasemeasure, basemeasure\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.ConstantBaseMeasure","page":"Interface","title":"ExponentialFamily.ConstantBaseMeasure","text":"A trait object representing that the base measure is constant.\n\n\n\n\n\n","category":"type"},{"location":"interface/#ExponentialFamily.NonConstantBaseMeasure","page":"Interface","title":"ExponentialFamily.NonConstantBaseMeasure","text":"A trait object representing that the base measure is not constant.\n\n\n\n\n\n","category":"type"},{"location":"interface/#Interfacing-with-Distributions-Defined-in-the-Distributions.jl-Package","page":"Interface","title":"Interfacing with Distributions Defined in the Distributions.jl Package","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"The Distributions.jl package is a comprehensive library that defines a wide collection of standard distributions. The main objective of the Distributions package is to offer a unified interface for evaluating likelihoods of various distributions, along with convenient sampling routines from these distributions. The ExponentialFamily package provides a lightweight interface for a subset of the distributions defined in the Distributions package.","category":"page"},{"location":"interface/#Conversion-between-Mean-Parameters-Space-and-Natural-Parameters-Space","page":"Interface","title":"Conversion between Mean Parameters Space and Natural Parameters Space","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"The Distributions package introduces the params function, which allows the retrieval of parameters for different distributions. For example:","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"using Distributions, ExponentialFamily\n\ndistribution = Bernoulli(0.25)\n\ntuple_of_θ = params(distribution)","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"These parameters are typically defined in what's known as the mean parameters space. However, the ExponentialFamilyDistribution expects parameters to be in the natural parameters space. To facilitate conversion between these two representations, the ExponentialFamily package provides two structures:","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"MeanToNatural\nNaturalToMean\nExponentialFamily.getmapping","category":"page"},{"location":"interface/#ExponentialFamily.MeanToNatural","page":"Interface","title":"ExponentialFamily.MeanToNatural","text":"MeanToNatural(::Type{T})\n\nReturn the transformation function that maps the parameters in the mean parameters space to the natural parameters space for a distribution of type T. The transformation function is of signature (params_in_mean_space, [ conditioner ]) -> params_in_natural_space.\n\nSee also: NaturalToMean, NaturalParametersSpace, MeanParametersSpace, getmapping\n\n\n\n\n\n","category":"type"},{"location":"interface/#ExponentialFamily.NaturalToMean","page":"Interface","title":"ExponentialFamily.NaturalToMean","text":"NaturalToMean(::Type{T})\n\nReturn the transformation function that maps the parameters in the natural parameters space to the mean parameters space for a distribution of type T. The transformation function is of signature (params_in_natural_space, [ conditioner ]) -> params_in_mean_space.\n\nSee also: MeanToNatural, NaturalParametersSpace, MeanParametersSpace, getmapping\n\n\n\n\n\n","category":"type"},{"location":"interface/#ExponentialFamily.getmapping","page":"Interface","title":"ExponentialFamily.getmapping","text":"getmapping(::Pair{L, R}, T)\n\nReturns a transformation L -> R between different parametrizations of a distribution of type T.\n\nSee also: NaturalParametersSpace, MeanParametersSpace, NaturalToMean, MeanToNatural\n\n\n\n\n\n","category":"function"},{"location":"interface/","page":"Interface","title":"Interface","text":"To convert from the mean parameters space to the corresponding natural parameters space, you can use the following code:","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"tuple_of_η = MeanToNatural(Bernoulli)(tuple_of_θ)","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"And to convert back:","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"tuple_of_θ = NaturalToMean(Bernoulli)(tuple_of_η)","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"Alternatuvely, the following API is supported ","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"map(MeanParametersSpace() => NaturalParametersSpace(), Bernoulli, tuple_of_θ)","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"map(NaturalParametersSpace() => MeanParametersSpace(), Bernoulli, tuple_of_η)","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"While the ExponentialFamily package employs the respective mappings where needed, it's also possible to call these functions manually. For instance, the generic implementation of the convert function between ExponentialFamilyDistribution and Distribution is built in terms of MeanToNatural and NaturalToMean. Moreover, the convert function performs checks to ensure that the provided parameters and conditioner are suitable for a specific distribution type.","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"isproper(::Type{T}, parameters, conditioner = nothing) where { T <: Distribution }","category":"page"},{"location":"interface/#ExponentialFamily.isproper-Union{Tuple{T}, Tuple{Type{T}, Any}, Tuple{Type{T}, Any, Any}} where T<:Distribution","page":"Interface","title":"ExponentialFamily.isproper","text":"isproper([ space = NaturalParametersSpace() ], ::Type{T}, parameters, conditioner = nothing) where { T <: Distribution }\n\nA specific verion of isproper defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.\n\nSee also: NaturalParametersSpace, MeanParametersSpace\n\n\n\n\n\n","category":"method"},{"location":"interface/#Note-on-the-conditioned-distributions","page":"Interface","title":"Note on the conditioned distributions","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"For the conditioned distributions, two additional functions separate_conditioner and join_conditioner are used to separate the conditioner and actual parameters returned from the Distributions.params function.","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"ExponentialFamily.separate_conditioner\nExponentialFamily.join_conditioner","category":"page"},{"location":"interface/#ExponentialFamily.separate_conditioner","page":"Interface","title":"ExponentialFamily.separate_conditioner","text":"separate_conditioner(::Type{T}, params) where {T <: Distribution}\n\nSeparates the conditioner argument from params and returns a tuple of (conditioned_params, conditioner). By default returns (params, nothing) but can be overwritten for certain distributions.\n\njulia> (cparams, conditioner) = ExponentialFamily.separate_conditioner(Laplace, (0.0, 1.0))\n((1.0,), 0.0)\n\njulia> params = ExponentialFamily.join_conditioner(Laplace, cparams, conditioner)\n(0.0, 1.0)\n\njulia> Laplace(params...) == Laplace(0.0, 1.0)\ntrue\n\nSee also: ExponentialFamily.join_conditioner\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.join_conditioner","page":"Interface","title":"ExponentialFamily.join_conditioner","text":"join_conditioner(::Type{T}, params, conditioner) where { T <: Distribution }\n\nJoins the conditioner argument with the params and returns a tuple of joined params, such that it can be used in a constructor of the T distribution.\n\njulia> (cparams, conditioner) = ExponentialFamily.separate_conditioner(Laplace, (0.0, 1.0))\n((1.0,), 0.0)\n\njulia> params = ExponentialFamily.join_conditioner(Laplace, cparams, conditioner)\n(0.0, 1.0)\n\njulia> Laplace(params...) == Laplace(0.0, 1.0)\ntrue\n\nSee also: ExponentialFamily.separate_conditioner\n\n\n\n\n\n","category":"function"},{"location":"interface/","page":"Interface","title":"Interface","text":"For example, Laplace distribution defines the functions in the following way","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"# `params` are coming from the `Distribution.params(::Laplace)` and return (location, scale)\n# The `location`, however is a fixed parameter in the exponential distribution representation of Laplace\n# Hence, we return a tuple of tuple of actual parameter and the conditioner\nfunction separate_conditioner(::Type{Laplace}, params)\n location, scale = params\n return ((scale, ), location)\nend\n\n# The `join_conditioner` must join the actual parameters and the conditioner in such a way, that it is compatible \n# with the `Laplace` structure from the `Distributions.jl`. In Laplace, the location parameter goes first.\nfunction join_conditioner(::Type{Laplace}, cparams, conditioner) \n (scale, ) = cparams\n location = conditioner\n return (location, scale)\nend","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"In general, all functions defined for the ExponentialFamilyDistribution, such as getlogpartition or getbasemeasure accept an optional conditioner parameter, which is assumed to be nothing. Conditioned distribution implement the \"conditioned\" versions of such functions by explicitly requiring the conditioner parameter, e.g.","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"getsufficientstatistics(Laplace, 1.0) # explicit `conditioner = 1.0`","category":"page"},{"location":"interface/#Efficient-packing-of-the-natural-parameters-into-a-vectorized-form","page":"Interface","title":"Efficient packing of the natural parameters into a vectorized form","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"The ExponentialFamilyDistribution type stores its natural parameters in a vectorized, or packed, format. This is done for the sake of efficiency and to enhance compatibility with autodiff packages like ForwardDiff, which anticipate a single parameter vector. As a result, the tuple of natural parameters needs to be converted to its corresponding vectorized form and vice versa. To achieve this, the package provides the flatten_parameters, pack_parameters and unpack_parameters functions.","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"ExponentialFamily.flatten_parameters\nExponentialFamily.pack_parameters\nExponentialFamily.unpack_parameters","category":"page"},{"location":"interface/#ExponentialFamily.flatten_parameters","page":"Interface","title":"ExponentialFamily.flatten_parameters","text":"flatten_parameters(::Type{T}, params::Tuple)\n\nThis function returns the parameters of a distribution of type T in a flattened form without actually allocating the container.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.pack_parameters","page":"Interface","title":"ExponentialFamily.pack_parameters","text":"pack_parameters([ space ], ::Type{T}, params::Tuple)\n\nThis function returns the parameters of a distribution of type T in a vectorized (packed) form. For most of the distributions the packed versions are of the same structure in any parameters space. For some distributions, however, it is necessary to indicate the space of the packaged parameters.\n\njulia> ExponentialFamily.pack_parameters((1, [2.0, 3.0], [4.0 5.0 6.0; 7.0 8.0 9.0]))\n9-element Vector{Float64}:\n 1.0\n 2.0\n 3.0\n 4.0\n 7.0\n 5.0\n 8.0\n 6.0\n 9.0\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.unpack_parameters","page":"Interface","title":"ExponentialFamily.unpack_parameters","text":"unpack_parameters([ space ], ::Type{T}, parameters)\n\nThis function \"unpack\" the vectorized form of the parameters in a tuple. For most of the distributions the packed parameters are of the same structure in any parameters space. For some distributions, however, it is necessary to indicate the space of the packaged parameters.\n\nSee also: MeanParametersSpace, NaturalParametersSpace\n\n\n\n\n\n","category":"function"},{"location":"interface/","page":"Interface","title":"Interface","text":"These functions are not exported by default, but it's important to note that the ExponentialFamilyDistributions type doesn't actually store the parameter tuple internally. Instead, the getnaturalparameters function returns the corresponding vectorized (packed) form of the natural parameters. In general, only the ExponentialFamily.unpack_parameters function must be implemented, as others could be implemented in a generic way.","category":"page"},{"location":"interface/#Attributes-of-the-exponential-family-distribution-based-on-Distribution","page":"Interface","title":"Attributes of the exponential family distribution based on Distribution","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"The ExponentialFamilyDistribution{T} where { T <: Distribution } type encompasses all fundamental attributes of the exponential family, including basemeasure, logpartition, sufficientstatistics, and fisherinformation. Furthermore, it's possible to retrieve the actual functions that compute these attributes. For instance, consider the following example:","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"basemeasure_of_bernoilli = getbasemeasure(Bernoulli)\n\nbasemeasure_of_bernoilli(0)","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"isproper(::Type{T}, parameters, conditioner) where {T <: Distribution}\ngetbasemeasure(::Type{T}, ::Nothing) where {T <: Distribution}\ngetsufficientstatistics(::Type{T}, ::Nothing) where { T <: Distribution }\ngetlogpartition(::Type{T}, _) where { T <: Distribution }\ngetfisherinformation(::Type{T}, _) where { T <: Distribution }","category":"page"},{"location":"interface/#ExponentialFamily.isproper-Union{Tuple{T}, Tuple{Type{T}, Any, Any}} where T<:Distribution","page":"Interface","title":"ExponentialFamily.isproper","text":"isproper([ space = NaturalParametersSpace() ], ::Type{T}, parameters, conditioner = nothing) where { T <: Distribution }\n\nA specific verion of isproper defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.\n\nSee also: NaturalParametersSpace, MeanParametersSpace\n\n\n\n\n\n","category":"method"},{"location":"interface/#ExponentialFamily.getbasemeasure-Union{Tuple{T}, Tuple{Type{T}, Nothing}} where T<:Distribution","page":"Interface","title":"ExponentialFamily.getbasemeasure","text":"getbasemeasure(::Type{<:Distribution}, [ conditioner ])\n\nA specific verion of getbasemeasure defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. For conditional exponential family distributions requires an extra conditioner argument.\n\n\n\n\n\n","category":"method"},{"location":"interface/#ExponentialFamily.getsufficientstatistics-Union{Tuple{T}, Tuple{Type{T}, Nothing}} where T<:Distribution","page":"Interface","title":"ExponentialFamily.getsufficientstatistics","text":"getsufficientstatistics(::Type{<:Distribution}, [ conditioner ])\n\nA specific verion of getsufficientstatistics defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. For conditional exponential family distributions requires an extra conditioner argument.\n\n\n\n\n\n","category":"method"},{"location":"interface/#ExponentialFamily.getlogpartition-Union{Tuple{T}, Tuple{Type{T}, Any}} where T<:Distribution","page":"Interface","title":"ExponentialFamily.getlogpartition","text":"getlogpartition([ space = NaturalParametersSpace() ], ::Type{T}, [ conditioner ]) where { T <: Distribution }\n\nA specific verion of getlogpartition defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.\n\nSee also: NaturalParametersSpace, MeanParametersSpace\n\n\n\n\n\n","category":"method"},{"location":"interface/#ExponentialFamily.getfisherinformation-Union{Tuple{T}, Tuple{Type{T}, Any}} where T<:Distribution","page":"Interface","title":"ExponentialFamily.getfisherinformation","text":"getfisherinformation([ space = NaturalParametersSpace() ], ::Type{T}) where { T <: Distribution }\n\nA specific verion of getfisherinformation defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.\n\nSee also: NaturalParametersSpace, MeanParametersSpace\n\n\n\n\n\n","category":"method"},{"location":"interface/","page":"Interface","title":"Interface","text":"Certain functions require knowledge about which parameter space is being used. By default, the NaturalParametersSpace is assumed.","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"getlogpartition(Bernoulli) === getlogpartition(NaturalParametersSpace(), Bernoulli)","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"NaturalParametersSpace\nMeanParametersSpace","category":"page"},{"location":"interface/#ExponentialFamily.NaturalParametersSpace","page":"Interface","title":"ExponentialFamily.NaturalParametersSpace","text":"NaturalParametersSpace\n\nSpecifies the natural parameters space η as the desired parameters space. Some functions (such as logpartition or fisherinformation) accept an additional space parameter to disambiguate the desired parameters space. Use map(NaturalParametersSpace() => MeanParametersSpace(), T, parameters, conditioner) to map the parameters and the conditioner of a distribution of type T from the natural parametrization to the corresponding mean parametrization.\n\nSee also: MeanParametersSpace, getmapping, NaturalToMean, MeanToNatural\n\n\n\n\n\n","category":"type"},{"location":"interface/#ExponentialFamily.MeanParametersSpace","page":"Interface","title":"ExponentialFamily.MeanParametersSpace","text":"MeanParametersSpace\n\nSpecifies the mean parameters space θ as the desired parameters space. Some functions (such as logpartition or fisherinformation) accept an additional space parameter to disambiguate the desired parameters space. Use map(MeanParametersSpace() => NaturalParametersSpace(), T, parameters, conditioner) to map the parameters and the conditioner of a distribution of type T from the mean parametrization to the corresponding natural parametrization.\n\nSee also: NaturalParametersSpace, getmapping, NaturalToMean, MeanToNatural\n\n\n\n\n\n","category":"type"},{"location":"interface/","page":"Interface","title":"Interface","text":"The isbasemeasureconstant function is defined for all supported distributions as well.","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"isbasemeasureconstant(Bernoulli)","category":"page"},{"location":"interface/#Extra-defined-distributions","page":"Interface","title":"Extra defined distributions","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"The package defines a list of extra distributions for a purpose of more efficiency in different circumstances. The list is available here.","category":"page"},{"location":"library/#library","page":"Library","title":"Library API","text":"","category":"section"},{"location":"library/#library-prod","page":"Library","title":"Product API","text":"","category":"section"},{"location":"library/","page":"Library","title":"Library","text":"One of the central functions in this package is the ability to calculate the product of two distributions over the same variable. You can also refer to the corresponding example for practical usage.","category":"page"},{"location":"library/","page":"Library","title":"Library","text":"The prod function is a key feature of this package. It accepts a strategy as its first argument, which defines how the prod function should behave and what results you can expect.","category":"page"},{"location":"library/","page":"Library","title":"Library","text":"prod(::ClosedProd, left, right)\nExponentialFamily.default_prod_rule","category":"page"},{"location":"library/#Base.prod-Tuple{ClosedProd, Any, Any}","page":"Library","title":"Base.prod","text":"prod(strategy, left, right)\n\nprod function is used to find a product of two probability distributions (or any other objects) over same variable (e.g. 𝓝(x|μ1, σ1) × 𝓝(x|μ2, σ2)). There are multiple strategies for prod function, e.g. ClosedProd, GenericProd or PreserveTypeProd.\n\nExamples:\n\njulia> product = prod(PreserveTypeProd(Distribution), NormalMeanVariance(-1.0, 1.0), NormalMeanVariance(1.0, 1.0))\nNormalWeightedMeanPrecision{Float64}(xi=0.0, w=2.0)\n\njulia> mean(product), var(product)\n(0.0, 0.5)\n\njulia> product = prod(PreserveTypeProd(NormalMeanVariance), NormalMeanVariance(-1.0, 1.0), NormalMeanVariance(1.0, 1.0))\nNormalMeanVariance{Float64}(μ=0.0, v=0.5)\n\njulia> mean(product), var(product)\n(0.0, 0.5)\n\njulia> product = prod(PreserveTypeProd(ExponentialFamilyDistribution), NormalMeanVariance(-1.0, 1.0), NormalMeanVariance(1.0, 1.0))\nExponentialFamily(NormalMeanVariance)\n\njulia> mean(product), var(product)\n(0.0, 0.5)\n\nSee also: default_prod_rule, ClosedProd, PreserveTypeProd, GenericProd\n\n\n\n\n\n","category":"method"},{"location":"library/#ExponentialFamily.default_prod_rule","page":"Library","title":"ExponentialFamily.default_prod_rule","text":"default_prod_rule(::Type, ::Type)\n\nReturns the most suitable prod rule for two given distribution types. Returns UnspecifiedProd by default.\n\nSee also: prod, ClosedProd, GenericProd\n\n\n\n\n\n","category":"function"},{"location":"library/#library-prod-strategies","page":"Library","title":"Product strategies","text":"","category":"section"},{"location":"library/","page":"Library","title":"Library","text":"For certain distributions, it's possible to compute the product using a straightforward mathematical equation, yielding a closed-form solution. However, for some distributions, finding a closed-form solution might not be feasible. Various strategies ensure consistent behavior in these situations. These strategies can either guarantee a fast and closed-form solution or, when necessary, fall back to a slower but more generic method.","category":"page"},{"location":"library/","page":"Library","title":"Library","text":"ExponentialFamily.UnspecifiedProd\nExponentialFamily.ClosedProd\nExponentialFamily.PreserveTypeProd\nExponentialFamily.PreserveTypeLeftProd\nExponentialFamily.PreserveTypeRightProd\nExponentialFamily.GenericProd\nExponentialFamily.ProductOf\nExponentialFamily.LinearizedProductOf","category":"page"},{"location":"library/#ExponentialFamily.UnspecifiedProd","page":"Library","title":"ExponentialFamily.UnspecifiedProd","text":"UnspecifiedProd\n\nA strategy for the prod function, which does not compute the prod, but instead fails in run-time and prints a descriptive error message.\n\nSee also: prod, ClosedProd, GenericProd\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.ClosedProd","page":"Library","title":"ExponentialFamily.ClosedProd","text":"ClosedProd\n\nClosedProd is one of the strategies for prod function. This strategy uses either PreserveTypeProd(Distribution) or PreserveTypeProd(ExponentialFamilyDistribution), depending on the types of the input arguments. For example, if both inputs are of type Distribution, then ClosedProd would fallback to PreserveTypeProd(Distribution).\n\nSee also: prod, PreserveTypeProd, GenericProd\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.PreserveTypeProd","page":"Library","title":"ExponentialFamily.PreserveTypeProd","text":"PreserveTypeProd{T}\n\nPreserveTypeProd is one of the strategies for prod function. This strategy constraint an output of a prod to be in some specific form. By default it uses the strategy from default_prod_rule and converts the output to the prespecified type but can be overwritten for some distributions for better performance.\n\njulia> product = prod(PreserveTypeProd(NormalMeanVariance), NormalMeanVariance(-1.0, 1.0), NormalMeanVariance(1.0, 1.0))\nNormalMeanVariance{Float64}(μ=0.0, v=0.5)\n\njulia> mean(product), var(product)\n(0.0, 0.5)\n\nSee also: prod, ClosedProd, PreserveTypeLeftProd, PreserveTypeRightProd, GenericProd\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.PreserveTypeLeftProd","page":"Library","title":"ExponentialFamily.PreserveTypeLeftProd","text":"PreserveTypeLeftProd\n\nAn alias for the PreserveTypeProd(L) where L is the type of the left argument of the prod function.\n\njulia> product = prod(PreserveTypeLeftProd(), NormalMeanVariance(-1.0, 1.0), NormalMeanPrecision(1.0, 1.0))\nNormalMeanVariance{Float64}(μ=0.0, v=0.5)\n\njulia> mean(product), var(product)\n(0.0, 0.5)\n\nSee also: prod, PreserveTypeProd, PreserveTypeRightProd, GenericProd\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.PreserveTypeRightProd","page":"Library","title":"ExponentialFamily.PreserveTypeRightProd","text":"PreserveTypeRightProd\n\nAn alias for the PreserveTypeProd(R) where R is the type of the right argument of the prod function. \n\njulia> product = prod(PreserveTypeRightProd(), NormalMeanVariance(-1.0, 1.0), NormalMeanPrecision(1.0, 1.0))\nNormalMeanPrecision{Float64}(μ=0.0, w=2.0)\n\njulia> mean(product), var(product)\n(0.0, 0.5)\n\nSee also: prod, PreserveTypeProd, PreserveTypeLeftProd, GenericProd\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.GenericProd","page":"Library","title":"ExponentialFamily.GenericProd","text":"GenericProd\n\nGenericProd is one of the strategies for prod function. This strategy does always produces a result, even if the closed form product is not availble, in which case simply returns the ProductOf object. GenericProd sometimes fallbacks to the default_prod_rule which it may or may not use under some circumstances. For example if the default_prod_rule is ClosedProd - GenericProd will try to optimize the tree with analytical closed solutions (if possible).\n\nSee also: prod, ProductOf, ClosedProd, PreserveTypeProd, default_prod_rule\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.ProductOf","page":"Library","title":"ExponentialFamily.ProductOf","text":"ProductOf\n\nA generic structure representing a product of two distributions. Can be viewed as a tuple of (left, right). Does not check nor supports neither variate forms during the creation stage. Uses the fuse_support function to fuse supports of two different distributions.\n\nThis object does not define any statistical properties (such as mean or var etc) and cannot be used as a distribution explicitly. Instead, it must be further approximated as a member of some other distribution. \n\nSee also: prod, GenericProd, ExponentialFamily.fuse_supports\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.LinearizedProductOf","page":"Library","title":"ExponentialFamily.LinearizedProductOf","text":"LinearizedProductOf\n\nAn efficient linearized implementation of product of multiple distributions. This structure prevents ProductOf tree from growing too much in case of identical objects. This trick significantly reduces Julia compilation times when closed product rules are not available but distributions are of the same type. Essentially this structure linearizes leaves of the ProductOf tree in case if it sees objects of the same type (via dispatch).\n\nSee also: ProductOf, [GenericProd]\n\n\n\n\n\n","category":"type"},{"location":"library/","page":"Library","title":"Library","text":"These strategies offer flexibility and reliability when working with different types of distributions, ensuring that the package can handle a wide range of cases effectively.","category":"page"},{"location":"library/#library-list-distributions-extra","page":"Library","title":"Additional distributions","text":"","category":"section"},{"location":"library/","page":"Library","title":"Library","text":"These are the distributions that are not included in the Distributions.jl package.","category":"page"},{"location":"library/","page":"Library","title":"Library","text":"ExponentialFamily.MatrixDirichlet\nExponentialFamily.GammaShapeRate\nExponentialFamily.GammaShapeScale\nExponentialFamily.NormalMeanPrecision\nExponentialFamily.NormalMeanVariance\nExponentialFamily.NormalWeightedMeanPrecision\nExponentialFamily.MvNormalMeanPrecision\nExponentialFamily.MvNormalMeanCovariance\nExponentialFamily.MvNormalWeightedMeanPrecision\nExponentialFamily.JointNormal\nExponentialFamily.WishartFast\nExponentialFamily.InverseWishartFast\nExponentialFamily.JointGaussian\nExponentialFamily.NormalGamma\nExponentialFamily.MvNormalWishart\nExponentialFamily.FactorizedJoint","category":"page"},{"location":"library/#ExponentialFamily.MatrixDirichlet","page":"Library","title":"ExponentialFamily.MatrixDirichlet","text":"MatrixDirichlet{T <: Real, A <: AbstractMatrix{T}} <: ContinuousMatrixDistribution\n\nA matrix-valued MatrixDirichlet distribution, where T is the element type of the matrix A. The a field stores the matrix parameter of the distribution.\n\nFields\n\na::A: The matrix parameter of the MatrixDirichlet distribution.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.GammaShapeRate","page":"Library","title":"ExponentialFamily.GammaShapeRate","text":"GammaShapeRate{T <: Real}\n\nA univariate gamma distribution parametrized by its shape a and rate b.\n\nFields\n\na: The shape parameter of the gamma distribution. It should be a positive real number.\nb: The rate parameter of the gamma distribution. It should be a positive real number.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.GammaShapeScale","page":"Library","title":"ExponentialFamily.GammaShapeScale","text":"GammaShapeScale{T}\n\nA continuous univariate gamma distribution parametrized by its shape α and scale β parameters.\n\nFields\n\nα: The shape parameter of the gamma distribution. It should be a positive real number.\nβ: The scale parameter of the gamma distribution. It should be a positive real number.\n\nNote\n\nGammaShapeScale is an alias for Gamma from Distributions.jl.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.NormalMeanPrecision","page":"Library","title":"ExponentialFamily.NormalMeanPrecision","text":"NormalMeanPrecision{T <: Real} <: ContinuousUnivariateDistribution\n\nA normal distribution with a known mean μ and precision w.\n\nFields\n\nμ::T: The mean of the normal distribution.\nw::T: The precision of the normal distribution.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.NormalMeanVariance","page":"Library","title":"ExponentialFamily.NormalMeanVariance","text":"NormalMeanVariance{T <: Real} <: ContinuousUnivariateDistribution\n\nA normal distribution with a known mean μ and variance v.\n\nFields\n\nμ::T: The mean of the normal distribution.\nv::T: The variance of the normal distribution.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.NormalWeightedMeanPrecision","page":"Library","title":"ExponentialFamily.NormalWeightedMeanPrecision","text":"NormalWeightedMeanPrecision{T <: Real} <: ContinuousUnivariateDistribution\n\nA normal distribution parametrized by its natural parameters: the weighted mean xi and precision w.\n\nFields\n\nxi::T: The weighted mean of the normal distribution. xi is computed as w * μ, where μ is the mean of the distribution.\nw::T: The precision (inverse variance) of the normal distribution.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.MvNormalMeanPrecision","page":"Library","title":"ExponentialFamily.MvNormalMeanPrecision","text":"MvNormalMeanPrecision{T <: Real, M <: AbstractVector{T}, P <: AbstractMatrix{T}} <: AbstractMvNormal\n\nA multivariate normal distribution with mean μ and precision matrix Λ, where T is the element type of the vectors M and matrices P.\n\nFields\n\nμ::M: The mean vector of the multivariate normal distribution.\nΛ::P: The precision matrix (inverse of the covariance matrix) of the multivariate normal distribution.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.MvNormalMeanCovariance","page":"Library","title":"ExponentialFamily.MvNormalMeanCovariance","text":"MvNormalMeanCovariance{T <: Real, M <: AbstractVector{T}, P <: AbstractMatrix{T}} <: AbstractMvNormal\n\nA multivariate normal distribution with mean μ and covariance matrix Σ, where T is the element type of the vectors M and matrices P.\n\nFields\n\nμ::M: The mean vector of the multivariate normal distribution.\nΣ::P: The covariance matrix of the multivariate normal distribution\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.MvNormalWeightedMeanPrecision","page":"Library","title":"ExponentialFamily.MvNormalWeightedMeanPrecision","text":"MvNormalWeightedMeanPrecision{T <: Real, M <: AbstractVector{T}, P <: AbstractMatrix{T}} <: AbstractMvNormal\n\nA multivariate normal distribution with a weighted mean vector xi and precision matrix Λ, where T is the element type of the vectors M and matrices P. This struct represents a natural parametrization of a multivariate Gaussian distribution.\n\nFields\n\nxi::M: The weighted mean vector of the multivariate normal distribution.\nΛ::P: The precision matrix (inverse of the covariance matrix) of the multivariate normal distribution.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.JointNormal","page":"Library","title":"ExponentialFamily.JointNormal","text":"JointNormal{D, S}\n\nJointNormal is an auxilary structure used for the joint marginal over Normally distributed variables. JointNormal stores a vector with the original dimensionalities (ds), so statistics can later be re-separated.\n\nUse ExponentialFamily.getcomponent(joint, index) to get a specific component of the joint distribution.\n\nFields\n\ndist: joint distribution (typically just a big MvNormal distribution, but maybe a tuple of individual means and covariance matrices)\nds: a tuple with the original dimensionalities of individual Normal distributions\nds[k] = (n,) where n is an integer indicates Multivariate normal of size n\nds[k] = () indicates Univariate normal\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.WishartFast","page":"Library","title":"ExponentialFamily.WishartFast","text":"WishartFast{T <: Real, A <: AbstractMatrix{T}} <: ContinuousMatrixDistribution\n\nThe WishartFast struct represents a fast version of the Wishart distribution. It is similar to the Wishart distribution from Distributions.jl, but it does not check input arguments, allowing the creation of improper Wishart messages.\n\nFor model creation and regular usage, it is recommended to use Wishart from Distributions.jl. The WishartFast distribution is intended for internal purposes and should not be directly used by regular users.\n\nFields\n\nν::T: The degrees of freedom parameter of the Wishart distribution.\ninvS::A: The inverse scale matrix parameter of the Wishart distribution.\n\nNote\n\nInternally, WishartFast stores and creates the inverse of its scale matrix. However, the params() function returns the scale matrix itself for backward compatibility. This is done to ensure better stability in the message passing update rules for ReactiveMP.jl.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.InverseWishartFast","page":"Library","title":"ExponentialFamily.InverseWishartFast","text":"InverseWishartFast{T <: Real, A <: AbstractMatrix{T}} <: ContinuousMatrixDistribution\n\nThe InverseWishartFast struct represents an improper Inverse Wishart distribution. It is similar to the InverseWishart distribution from Distributions.jl, but it does not check input arguments, allowing the creation of improper InverseWishart messages. \n\nFor model creation and regular usage, it is recommended to use InverseWishart from Distributions.jl. The InverseWishartFast distribution is intended for internal purposes and should not be directly used by regular users.\n\nFields\n\nν::T: The degrees of freedom parameter of the inverse Wishart distribution.\nS::A: The scale matrix parameter of the inverse Wishart distribution.\n\nNote\n\nThe InverseWishartFast distribution does not enforce input argument validation, making it suitable for specialized cases where improper message constructions are needed.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.JointGaussian","page":"Library","title":"ExponentialFamily.JointGaussian","text":"An alias for the JointNormal.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.NormalGamma","page":"Library","title":"ExponentialFamily.NormalGamma","text":"NormalGamma{T <: Real} <: ContinuousMultivariateDistribution\n\nA normal-gamma distribution, where T is a real number. This distribution is a joint distribution of a normal random variable with mean μ and precision λ, and a gamma-distributed random variable with shape α and rate β.\n\nFields\n\nμ::T: The mean of the normal distribution.\nλ::T: The precision of the normal distribution.\nα::T: The shape parameter of the gamma distribution.\nβ::T: The rate parameter of the gamma distribution.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.MvNormalWishart","page":"Library","title":"ExponentialFamily.MvNormalWishart","text":"MvNormalWishart{T, M <: AbstractArray{T}, V <: AbstractMatrix{T}, K <: Real, N <: Real} <: ContinuousMatrixDistribution\n\nA multivariate normal-Wishart distribution, where T is the element type of the arrays M and matrices V, and K and N are real numbers. This distribution is a joint distribution of a multivariate normal random variable with mean μ and a Wishart-distributed random matrix with scale matrix Ψ, degrees of freedom ν, and the scalar κ as a scaling parameter.\n\nFields\n\nμ::M: The mean vector of the multivariate normal distribution.\nΨ::V: The scale matrix of the Wishart distribution.\nκ::K: The scaling parameter of the Wishart distribution.\nν::N: The degrees of freedom of the Wishart distribution\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.FactorizedJoint","page":"Library","title":"ExponentialFamily.FactorizedJoint","text":"FactorizedJoint\n\nFactorizedJoint represents a joint distribution of independent random variables. Use getindex() function or square-brackets indexing to access the marginal distribution for individual variables.\n\n\n\n\n\n","category":"type"},{"location":"library/#library-promotion-utilities","page":"Library","title":"Promotion type utilities","text":"","category":"section"},{"location":"library/","page":"Library","title":"Library","text":"ExponentialFamily.paramfloattype\nExponentialFamily.sampletype\nExponentialFamily.samplefloattype\nExponentialFamily.promote_variate_type\nExponentialFamily.promote_paramfloattype\nExponentialFamily.promote_sampletype\nExponentialFamily.promote_samplefloattype\nExponentialFamily.convert_paramfloattype","category":"page"},{"location":"library/#ExponentialFamily.paramfloattype","page":"Library","title":"ExponentialFamily.paramfloattype","text":"paramfloattype(distribution)\n\nReturns the underlying float type of distribution's parameters.\n\nSee also: ExponentialFamily.promote_paramfloattype, ExponentialFamily.convert_paramfloattype\n\n\n\n\n\n","category":"function"},{"location":"library/#ExponentialFamily.sampletype","page":"Library","title":"ExponentialFamily.sampletype","text":"sampletype(distribution)\n\nReturns a type of the distribution. By default fallbacks to the eltype.\n\nSee also: ExponentialFamily.samplefloattype, ExponentialFamily.promote_sampletype, ExponentialFamily.promote_samplefloattype\n\n\n\n\n\n","category":"function"},{"location":"library/#ExponentialFamily.samplefloattype","page":"Library","title":"ExponentialFamily.samplefloattype","text":"samplefloattype(distribution)\n\nReturns a type of the distribution or the underlying float type in case if sample is Multivariate or Matrixvariate. By default fallbacks to the deep_eltype(sampletype(distribution)).\n\nSee also: ExponentialFamily.sampletype, ExponentialFamily.promote_sampletype, ExponentialFamily.promote_samplefloattype\n\n\n\n\n\n","category":"function"},{"location":"library/#ExponentialFamily.promote_variate_type","page":"Library","title":"ExponentialFamily.promote_variate_type","text":"promote_variate_PromoteTypeConverter(::Type{ <: VariateForm }, distribution_type)\n\nPromotes (if possible) a distribution_type to be of the specified variate form.\n\n\n\n\n\n","category":"function"},{"location":"library/#ExponentialFamily.promote_paramfloattype","page":"Library","title":"ExponentialFamily.promote_paramfloattype","text":"promote_paramfloattype(distributions...)\n\nPromotes paramfloattype of the distributions to a single type. See also promote_type.\n\nSee also: ExponentialFamily.paramfloattype, ExponentialFamily.convert_paramfloattype\n\n\n\n\n\n","category":"function"},{"location":"library/#ExponentialFamily.promote_sampletype","page":"Library","title":"ExponentialFamily.promote_sampletype","text":"promote_sampletype(distributions...)\n\nPromotes sampletype of the distributions to a single type. See also promote_type.\n\nSee also: ExponentialFamily.sampletype, ExponentialFamily.samplefloattype, ExponentialFamily.promote_samplefloattype\n\n\n\n\n\n","category":"function"},{"location":"library/#ExponentialFamily.promote_samplefloattype","page":"Library","title":"ExponentialFamily.promote_samplefloattype","text":"promote_samplefloattype(distributions...)\n\nPromotes samplefloattype of the distributions to a single type. See also promote_type.\n\nSee also: ExponentialFamily.sampletype, ExponentialFamily.samplefloattype, ExponentialFamily.promote_sampletype\n\n\n\n\n\n","category":"function"},{"location":"library/#ExponentialFamily.convert_paramfloattype","page":"Library","title":"ExponentialFamily.convert_paramfloattype","text":"convert_paramfloattype(::Type{T}, distribution)\n\nConverts (if possible) the params float type of the distribution to be of type T.\n\nSee also: ExponentialFamily.paramfloattype, ExponentialFamily.promote_paramfloattype\n\n\n\n\n\nconvert_paramfloattype(::Type{T}, container)\n\nConverts (if possible) the elements of the container to be of type T.\n\n\n\n\n\n","category":"function"},{"location":"library/#library-statsfuns","page":"Library","title":"Extra stats functions","text":"","category":"section"},{"location":"library/","page":"Library","title":"Library","text":"ExponentialFamily.mirrorlog\nExponentialFamily.xtlog\nExponentialFamily.logmvbeta\nExponentialFamily.clamplog\nExponentialFamily.mvtrigamma","category":"page"},{"location":"library/#ExponentialFamily.mirrorlog","page":"Library","title":"ExponentialFamily.mirrorlog","text":"mirrorlog(x)\n\nReturns log(1 - x).\n\n\n\n\n\n","category":"function"},{"location":"library/#ExponentialFamily.xtlog","page":"Library","title":"ExponentialFamily.xtlog","text":"xtlog(x)\n\nReturns x * log(x).\n\n\n\n\n\n","category":"function"},{"location":"library/#ExponentialFamily.logmvbeta","page":"Library","title":"ExponentialFamily.logmvbeta","text":"logmvbeta(x)\n\nUses the numerically stable algorithm to compute the logarithm of the multivariate beta distribution over with the parameter vector x.\n\n\n\n\n\n","category":"function"},{"location":"library/#ExponentialFamily.clamplog","page":"Library","title":"ExponentialFamily.clamplog","text":"clamplog(x)\n\nSame as log but clamps the input argument x to be in the range tiny <= x <= typemax(x) such that log(0) does not explode.\n\n\n\n\n\n","category":"function"},{"location":"library/#ExponentialFamily.mvtrigamma","page":"Library","title":"ExponentialFamily.mvtrigamma","text":"mvtrigamma(p, x)\n\nComputes multivariate trigamma function .\n\n\n\n\n\n","category":"function"},{"location":"library/#library-helpers","page":"Library","title":"Helper utilities","text":"","category":"section"},{"location":"library/","page":"Library","title":"Library","text":"ExponentialFamily.vague\nExponentialFamily.logpdf_sample_optimized\nExponentialFamily.fuse_supports","category":"page"},{"location":"library/#ExponentialFamily.vague","page":"Library","title":"ExponentialFamily.vague","text":"vague(distribution_type, [ dims... ])\n\nvague function returns uninformative probability distribution of a given type.\n\n\n\n\n\n","category":"function"},{"location":"library/#ExponentialFamily.logpdf_sample_optimized","page":"Library","title":"ExponentialFamily.logpdf_sample_optimized","text":"logpdf_sample_optimized(distribution)\n\nlogpdf_sample_optimized function takes as an input a distribution and returns corresponding optimized two versions for taking logpdf() and sampling with rand! respectively. By default returns the same distribution, but some distributions may override default behaviour for better efficiency.\n\nExample\n\njulia> d = vague(MvNormalMeanPrecision, 2)\nMvNormalMeanPrecision(\nμ: [0.0, 0.0]\nΛ: [1.0e-12 0.0; 0.0 1.0e-12]\n)\n\n\njulia> ExponentialFamily.logpdf_sample_optimized(d)\n(FullNormal(\ndim: 2\nμ: [0.0, 0.0]\nΣ: [1.0e12 -0.0; -0.0 1.0e12]\n)\n, FullNormal(\ndim: 2\nμ: [0.0, 0.0]\nΣ: [1.0e12 -0.0; -0.0 1.0e12]\n)\n)\n\n\n\n\n\n","category":"function"},{"location":"library/#ExponentialFamily.fuse_supports","page":"Library","title":"ExponentialFamily.fuse_supports","text":"fuse_supports(left, right)\n\nFuse supports of two distributions of left and right. By default, checks that the supports are identical and throws an error otherwise. Can implement specific fusions for specific distributions.\n\nSee also: prod, ProductOf\n\n\n\n\n\n","category":"function"},{"location":"examples/#examples","page":"Examples","title":"Examples","text":"","category":"section"},{"location":"examples/#examples-product","page":"Examples","title":"Product of two probability distributions over the same variable","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"In this example, we'll show you how to use the ExponentialFamily package to calculate the product of probability distributions that both relate to the same variable \"X\". This operation results in another probability distribution, also centered around the variable \"X\". It's essential to note that this is distinct from multiplying probability distributions for two different variables, such as \"X\" and \"Y\", which yields a joint probability distribution. Calculating the product of two probability distributions over the same variable is a crucial step in applying Bayes' rule.","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"p(Xvert D) propto underbracep(X)p(DX)_mathrmproductoftwodistributions","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"To perform this operation, the ExponentialFamily library employs the prod function. This function takes a product strategy as its first argument. For instance:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"using ExponentialFamily, Distributions\n\nprior = Bernoulli(0.5)\nlikelihood = Bernoulli(0.6)\n\nposterior = prod(PreserveTypeProd(Distribution), prior, likelihood)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"You can achieve the same result in the general exponential family form, which operates within the natural parameter space:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"\nef_prior = convert(ExponentialFamilyDistribution, prior)\nef_likelihood = convert(ExponentialFamilyDistribution, likelihood)\n\nef_posterior = prod(PreserveTypeProd(ExponentialFamilyDistribution), ef_prior, ef_likelihood)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"Or even more concisely:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"prod(PreserveTypeProd(ExponentialFamilyDistribution), prior, likelihood)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"In this example, multiplying two Bernoulli distributions will always result in another Bernoulli distribution. However, this is not the case for all distributions. For instance, the product of two Laplace distributions may not yield another Laplace distribution, and representing the result in the same form might not be possible. In such cases, it's advisable to calculate the result within the exponential family domain. This is because the product of two exponential family distributions can always be represented as another exponential family distribution, as shown here:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"\nprior = Laplace(2.0, 3.0)\nlikelihood = Laplace(1.0, 4.0)\n\nprod(PreserveTypeProd(ExponentialFamilyDistribution), prior, likelihood)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"Note that the result does not correspond to the Laplace distribution and returns a generic univariate ExponentialFamilyDistribution. This approach ensures consistency and compatibility, especially when dealing with a wide range of probability distributions.","category":"page"},{"location":"examples/#Computing-various-useful-attributes-of-an-exponential-family-member","page":"Examples","title":"Computing various useful attributes of an exponential family member","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"The package implements attributes of many well known exponential family members, which are defined in this table. The attributes include getbasemeasure, getsufficientstatistics, getlogpartition, getfisherinformation, and others. In general, the interface for these functions assumes a family member \"tag,\" such as Normal or Bernoulli. Here are some examples of how to use these attributes:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"using ExponentialFamily, Distributions\n\n# Returns a function\nbasemeasure_of_normal = getbasemeasure(Normal)\n\nbasemeasure_of_normal(0.0)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"\n# Returns an iterable of functions\nsufficientstatistics_of_gamma = getsufficientstatistics(Gamma)\n\nmap(f -> f(1.0), sufficientstatistics_of_gamma)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"Some distributions, like the Laplace distribution, qualify as exponential family members only under certain conditions or when specific information is known in advance. In such cases, the ExponentialFamily package introduces the concept of a conditioner. For instance, the Laplace distribution becomes a member of the exponential family only when the location parameter is known and fixed. Consequently, we condition on the location parameter:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"laplace = Laplace(2.0, 1.0)\n\ncanonical = convert(ExponentialFamilyDistribution, laplace)\n\ngetconditioner(canonical)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"# For conditioned distributions, the `conditioner` must be present as a second argument\nbasemeasure_of_laplace = getbasemeasure(Laplace, 2.0)\n\nbasemeasure_of_laplace(1.0)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"The getlogpartition and getfisherinformation functions optionally accept a space parameter as the first argument. This space parameter specifies the parameterization space, such as MeanParametersSpace or [NaturalParametersSpace]. The result obtained from these functions (in general) depends on the chosen parameter space:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"logpartition_of_gamma_in_mean_space = getlogpartition(MeanParametersSpace(), Gamma)\n\ngamma_parameters_in_mean_space = [ 1.0, 2.0 ]\n\nlogpartition_of_gamma_in_mean_space(gamma_parameters_in_mean_space)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"logparition_of_gamma_in_natural_space = getlogpartition(NaturalParametersSpace(), Gamma)\n\ngamma_parameters_in_natural_space = map(\n MeanParametersSpace() => NaturalParametersSpace(), \n Gamma,\n gamma_parameters_in_mean_space\n)\n\nlogparition_of_gamma_in_natural_space(gamma_parameters_in_natural_space)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"The same principle applies to the Fisher information matrix:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"fisherinformation_of_gamma_in_mean_space = getfisherinformation(MeanParametersSpace(), Gamma)\n\nfisherinformation_of_gamma_in_mean_space(gamma_parameters_in_mean_space)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"fisherinformation_of_gamma_in_natural_space = getfisherinformation(NaturalParametersSpace(), Gamma)\n\nfisherinformation_of_gamma_in_natural_space(gamma_parameters_in_natural_space)","category":"page"},{"location":"examples/#Approximating-attributes","page":"Examples","title":"Approximating attributes","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"Refer to the ExpectationApproximations.jl package for approximating various attributes of the members of the exponential family.","category":"page"},{"location":"#ExponentialFamily.jl","page":"Home","title":"ExponentialFamily.jl","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Julia package that extends the functionality of Distributions.jl by providing a collection of exponential family distributions and customized implementations. It is designed to facilitate working with exponential family distributions and offers specialized functionality tailored to this class of distributions.","category":"page"},{"location":"#Core-Principles","page":"Home","title":"Core Principles","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"The package is built around several core principles:","category":"page"},{"location":"","page":"Home","title":"Home","text":"High performance with minimal allocations, striving for complete type stability.\nCompatibility with distributions defined in Distributions.jl.\nEase of use and rich functionality.","category":"page"},{"location":"#Table-of-Contents","page":"Home","title":"Table of Contents","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Interface\nExamples\nLibrary","category":"page"},{"location":"#Index","page":"Home","title":"Index","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"","category":"page"}] +[{"location":"interface/#interface","page":"Interface","title":"The ExponentialFamilyDistribution Interface","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"This page describes the philosophy and design concepts behind the ExponentialFamilyDistribution interface. In a nutshell, the primary purpose of the ExponentialFamily package is to provide a generic interface for an ExponentialFamilyDistribution. It is beneficial to become familiar with the Wikipedia article on the exponential family before delving into the implementation details of this package.","category":"page"},{"location":"interface/#Notation","page":"Interface","title":"Notation","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"In the context of the package, exponential family distributions are represented in the form:","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"f_X(xmideta) = h(x) cdot expleft eta cdot T(x) - A(eta) right","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"Here:","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"h(x) is the base measure.\nT(x) represents sufficient statistics.\nA(η) stands for the log partition.\nη denotes the natural parameters.","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"In the following discussion we also use the following convention","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"η corresponds to the distribution's natural parameters in the natural parameter space.\nθ corresponds to the distribution's mean parameters in the mean parameter space.","category":"page"},{"location":"interface/#ExponentialFamilyDistribution-structure","page":"Interface","title":"ExponentialFamilyDistribution structure","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"ExponentialFamilyDistribution\nExponentialFamilyDistributionAttributes\nlogpdf(ef::ExponentialFamilyDistribution, x)\npdf(ef::ExponentialFamilyDistribution, x)\ncdf(ef::ExponentialFamilyDistribution{D}, x) where {D <: Distribution}\ngetnaturalparameters\ngetattributes\ngetconditioner\nisproper\ngetbasemeasure\ngetsufficientstatistics\ngetlogpartition\ngetfisherinformation\ngetsupport\nbasemeasure\nsufficientstatistics\nlogpartition\nfisherinformation\nisbasemeasureconstant\nConstantBaseMeasure\nNonConstantBaseMeasure","category":"page"},{"location":"interface/#ExponentialFamily.ExponentialFamilyDistribution","page":"Interface","title":"ExponentialFamily.ExponentialFamilyDistribution","text":"ExponentialFamilyDistribution(::Type{T}, naturalparameters, conditioner, attributes)\n\nExponentialFamilyDistribution structure represents a generic exponential family distribution in natural parameterization. Type T can be either a distribution type (e.g. from the Distributions.jl package) or a variate type (e.g. Univariate). In the context of the package, exponential family distributions are represented in the form:\n\npₓ(x η) = h(x) exp η T(x) - A(η) \n\nHere:\n\nh(x) is the base measure.\nT(x) represents sufficient statistics.\nA(η) stands for the log partition.\nη denotes the natural parameters.\n\nFor a given member of exponential family: \n\ngetattributes returns either nothing or ExponentialFamilyDistributionAttributes.\ngetbasemeasure returns a positive a valued function. \ngetsufficientstatistics returns an iterable of functions such as [x, x^2] or [x, logx].\ngetnaturalparameters returns an iterable holding the values of the natural parameters. \ngetlogpartition return a function that depends on the naturalparameters and it ensures that the distribution is normalized to 1. \ngetsupport returns the set that the distribution is defined over. Could be real numbers, positive integers, 3d cube etc. Use ither the ∈ operator or the insupport() function to check if a value belongs to the support.\n\nnote: Note\nThe attributes can be nothing. In which case the package will try to derive the corresponding attributes from the type T.\n\njulia> ef = convert(ExponentialFamilyDistribution, Bernoulli(0.5))\nExponentialFamily(Bernoulli)\n\njulia> getsufficientstatistics(ef)\n(identity,)\n\njulia> ef = convert(ExponentialFamilyDistribution, Laplace(1.0, 0.5))\nExponentialFamily(Laplace, conditioned on 1.0)\n\njulia> logpdf(ef, 4.0)\n-6.0\n\nSee also: getbasemeasure, getsufficientstatistics, getnaturalparameters, getlogpartition, getsupport\n\n\n\n\n\n","category":"type"},{"location":"interface/#ExponentialFamily.ExponentialFamilyDistributionAttributes","page":"Interface","title":"ExponentialFamily.ExponentialFamilyDistributionAttributes","text":"ExponentialFamilyDistributionAttributes(basemeasure, sufficientstatistics, logpartition, support)\n\nA structure to represent the attributes of an exponential family member.\n\nFields\n\nbasemeasure::B: The basemeasure of the exponential family member.\nsufficientstatistics::S: The sufficient statistics of the exponential family member.\nlogpartition::L: The log-partition (cumulant) of the exponential family member.\nsupport::P: The support of the exponential family member.\n\nSee also: ExponentialFamilyDistribution, getbasemeasure, getsufficientstatistics, getlogpartition, getsupport\n\n\n\n\n\n","category":"type"},{"location":"interface/#Distributions.logpdf-Tuple{ExponentialFamilyDistribution, Any}","page":"Interface","title":"Distributions.logpdf","text":"logpdf(ef::ExponentialFamilyDistribution, x)\n\nEvaluates and returns the log-density of the exponential family distribution for the input x.\n\n\n\n\n\n","category":"method"},{"location":"interface/#Distributions.pdf-Tuple{ExponentialFamilyDistribution, Any}","page":"Interface","title":"Distributions.pdf","text":"pdf(ef::ExponentialFamilyDistribution, x)\n\nEvaluates and returns the probability density function of the exponential family distribution for the input x.\n\n\n\n\n\n","category":"method"},{"location":"interface/#Distributions.cdf-Union{Tuple{D}, Tuple{ExponentialFamilyDistribution{D}, Any}} where D<:Distribution","page":"Interface","title":"Distributions.cdf","text":"cdf(ef::ExponentialFamilyDistribution{D}, x) where { D <: Distribution }\n\nEvaluates and returns the cumulative distribution function of the exponential family distribution for the input x.\n\n\n\n\n\n","category":"method"},{"location":"interface/#ExponentialFamily.getnaturalparameters","page":"Interface","title":"ExponentialFamily.getnaturalparameters","text":"getnaturalparameters(::ExponentialFamilyDistribution)\n\nGet the natural parameters of the exponential family distribution.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.getattributes","page":"Interface","title":"ExponentialFamily.getattributes","text":"getattributes(::ExponentialFamilyDistribution)\n\nReturns iether the attributes of the exponential family member or nothing. \n\nSee also: ExponentialFamilyDistributionAttributes\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.getconditioner","page":"Interface","title":"ExponentialFamily.getconditioner","text":"getconditioner(::ExponentialFamilyDistribution)\n\nReturns either the conditioner of the exponential family distribution or nothing. conditioner is a fixed parameter that is used to ensure that the distribution belongs to the exponential family.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.isproper","page":"Interface","title":"ExponentialFamily.isproper","text":"isproper(::ExponentialFamilyDistribution)\n\nChecks if the object of type ExponentialFamilyDistribution is a proper distribution.\n\n\n\n\n\nisproper([ space = NaturalParametersSpace() ], ::Type{T}, parameters, conditioner = nothing) where { T <: Distribution }\n\nA specific verion of isproper defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.\n\nSee also: NaturalParametersSpace, MeanParametersSpace\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.getbasemeasure","page":"Interface","title":"ExponentialFamily.getbasemeasure","text":"getbasemeasure(::ExponentialFamilyDistribution)\ngetbasemeasure(::Type{ <: Distribution }, [ conditioner ])\n\nReturns the base measure function of the exponential family distribution.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.getsufficientstatistics","page":"Interface","title":"ExponentialFamily.getsufficientstatistics","text":"getsufficientstatistics(::ExponentialFamilyDistribution)\ngetsufficientstatistics(::Type{ <: Distribution }, [ conditioner ])\n\nReturns the list of sufficient statistics of the exponential family distribution.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.getlogpartition","page":"Interface","title":"ExponentialFamily.getlogpartition","text":"getlogpartition(::ExponentialFamilyDistribution)\ngetlogpartition([ space ], ::Type{ <: Distribution }, [ conditioner ])\n\nReturns the log partition function of the exponential family distribution.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.getfisherinformation","page":"Interface","title":"ExponentialFamily.getfisherinformation","text":"getfisherinformation(::ExponentialFamilyDistribution)\ngetfisherinformation([ space ], ::Type{ <: Distribution }, [ conditioner ])\n\nReturns the function that computes the fisher information matrix of the exponential family distribution.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.getsupport","page":"Interface","title":"ExponentialFamily.getsupport","text":"getsupport(distribution_or_type)\n\nReturns the support of the exponential family distribution.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.basemeasure","page":"Interface","title":"ExponentialFamily.basemeasure","text":"basemeasure(::ExponentialFamilyDistribution, x)\n\nReturns the computed value of basemeasure of the exponential family distribution at the point x.\n\nSee also: getbasemeasure\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.sufficientstatistics","page":"Interface","title":"ExponentialFamily.sufficientstatistics","text":"sufficientstatistics(::ExponentialFamilyDistribution)\n\nReturns the computed values of sufficientstatistics of the exponential family distribution at the point x.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.logpartition","page":"Interface","title":"ExponentialFamily.logpartition","text":"logpartition(::ExponentialFamilyDistribution, η)\n\nReturn the computed value of logpartition of the exponential family distribution at the point η. By default η = getnaturalparameters(ef).\n\nSee also: getlogpartition\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.fisherinformation","page":"Interface","title":"ExponentialFamily.fisherinformation","text":"fisherinformation(distribution, η)\n\nReturn the computed value of fisherinformation of the exponential family distribution at the point η By default η = getnaturalparameters(ef).\n\nSee also: getfisherinformation\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.isbasemeasureconstant","page":"Interface","title":"ExponentialFamily.isbasemeasureconstant","text":"isbasemeasureconstant(something)\n\nReturns either NonConstantBaseMeasure() or ConstantBaseMeasure() depending on if the base measure is a constant with respect to the natural parameters of something or not. By default the package assumes that any base measure in a form of the Function is not a constant. It, however, is not true for basemeasure that simply return a constant. In such cases the isbasemeasureconstant must have a specific method.\n\nSee also: getbasemeasure, basemeasure\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.ConstantBaseMeasure","page":"Interface","title":"ExponentialFamily.ConstantBaseMeasure","text":"A trait object representing that the base measure is constant.\n\n\n\n\n\n","category":"type"},{"location":"interface/#ExponentialFamily.NonConstantBaseMeasure","page":"Interface","title":"ExponentialFamily.NonConstantBaseMeasure","text":"A trait object representing that the base measure is not constant.\n\n\n\n\n\n","category":"type"},{"location":"interface/#Interfacing-with-Distributions-Defined-in-the-Distributions.jl-Package","page":"Interface","title":"Interfacing with Distributions Defined in the Distributions.jl Package","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"The Distributions.jl package is a comprehensive library that defines a wide collection of standard distributions. The main objective of the Distributions package is to offer a unified interface for evaluating likelihoods of various distributions, along with convenient sampling routines from these distributions. The ExponentialFamily package provides a lightweight interface for a subset of the distributions defined in the Distributions package.","category":"page"},{"location":"interface/#Conversion-between-Mean-Parameters-Space-and-Natural-Parameters-Space","page":"Interface","title":"Conversion between Mean Parameters Space and Natural Parameters Space","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"The Distributions package introduces the params function, which allows the retrieval of parameters for different distributions. For example:","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"using Distributions, ExponentialFamily\n\ndistribution = Bernoulli(0.25)\n\ntuple_of_θ = params(distribution)","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"These parameters are typically defined in what's known as the mean parameters space. However, the ExponentialFamilyDistribution expects parameters to be in the natural parameters space. To facilitate conversion between these two representations, the ExponentialFamily package provides two structures:","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"MeanToNatural\nNaturalToMean\nExponentialFamily.getmapping","category":"page"},{"location":"interface/#ExponentialFamily.MeanToNatural","page":"Interface","title":"ExponentialFamily.MeanToNatural","text":"MeanToNatural(::Type{T})\n\nReturn the transformation function that maps the parameters in the mean parameters space to the natural parameters space for a distribution of type T. The transformation function is of signature (params_in_mean_space, [ conditioner ]) -> params_in_natural_space.\n\nSee also: NaturalToMean, NaturalParametersSpace, MeanParametersSpace, getmapping\n\n\n\n\n\n","category":"type"},{"location":"interface/#ExponentialFamily.NaturalToMean","page":"Interface","title":"ExponentialFamily.NaturalToMean","text":"NaturalToMean(::Type{T})\n\nReturn the transformation function that maps the parameters in the natural parameters space to the mean parameters space for a distribution of type T. The transformation function is of signature (params_in_natural_space, [ conditioner ]) -> params_in_mean_space.\n\nSee also: MeanToNatural, NaturalParametersSpace, MeanParametersSpace, getmapping\n\n\n\n\n\n","category":"type"},{"location":"interface/#ExponentialFamily.getmapping","page":"Interface","title":"ExponentialFamily.getmapping","text":"getmapping(::Pair{L, R}, T)\n\nReturns a transformation L -> R between different parametrizations of a distribution of type T.\n\nSee also: NaturalParametersSpace, MeanParametersSpace, NaturalToMean, MeanToNatural\n\n\n\n\n\n","category":"function"},{"location":"interface/","page":"Interface","title":"Interface","text":"To convert from the mean parameters space to the corresponding natural parameters space, you can use the following code:","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"tuple_of_η = MeanToNatural(Bernoulli)(tuple_of_θ)","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"And to convert back:","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"tuple_of_θ = NaturalToMean(Bernoulli)(tuple_of_η)","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"Alternatuvely, the following API is supported ","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"map(MeanParametersSpace() => NaturalParametersSpace(), Bernoulli, tuple_of_θ)","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"map(NaturalParametersSpace() => MeanParametersSpace(), Bernoulli, tuple_of_η)","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"While the ExponentialFamily package employs the respective mappings where needed, it's also possible to call these functions manually. For instance, the generic implementation of the convert function between ExponentialFamilyDistribution and Distribution is built in terms of MeanToNatural and NaturalToMean. Moreover, the convert function performs checks to ensure that the provided parameters and conditioner are suitable for a specific distribution type.","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"isproper(::Type{T}, parameters, conditioner = nothing) where { T <: Distribution }","category":"page"},{"location":"interface/#ExponentialFamily.isproper-Union{Tuple{T}, Tuple{Type{T}, Any}, Tuple{Type{T}, Any, Any}} where T<:Distribution","page":"Interface","title":"ExponentialFamily.isproper","text":"isproper([ space = NaturalParametersSpace() ], ::Type{T}, parameters, conditioner = nothing) where { T <: Distribution }\n\nA specific verion of isproper defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.\n\nSee also: NaturalParametersSpace, MeanParametersSpace\n\n\n\n\n\n","category":"method"},{"location":"interface/#Note-on-the-conditioned-distributions","page":"Interface","title":"Note on the conditioned distributions","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"For the conditioned distributions, two additional functions separate_conditioner and join_conditioner are used to separate the conditioner and actual parameters returned from the Distributions.params function.","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"ExponentialFamily.separate_conditioner\nExponentialFamily.join_conditioner","category":"page"},{"location":"interface/#ExponentialFamily.separate_conditioner","page":"Interface","title":"ExponentialFamily.separate_conditioner","text":"separate_conditioner(::Type{T}, params) where {T <: Distribution}\n\nSeparates the conditioner argument from params and returns a tuple of (conditioned_params, conditioner). By default returns (params, nothing) but can be overwritten for certain distributions.\n\njulia> (cparams, conditioner) = ExponentialFamily.separate_conditioner(Laplace, (0.0, 1.0))\n((1.0,), 0.0)\n\njulia> params = ExponentialFamily.join_conditioner(Laplace, cparams, conditioner)\n(0.0, 1.0)\n\njulia> Laplace(params...) == Laplace(0.0, 1.0)\ntrue\n\nSee also: ExponentialFamily.join_conditioner\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.join_conditioner","page":"Interface","title":"ExponentialFamily.join_conditioner","text":"join_conditioner(::Type{T}, params, conditioner) where { T <: Distribution }\n\nJoins the conditioner argument with the params and returns a tuple of joined params, such that it can be used in a constructor of the T distribution.\n\njulia> (cparams, conditioner) = ExponentialFamily.separate_conditioner(Laplace, (0.0, 1.0))\n((1.0,), 0.0)\n\njulia> params = ExponentialFamily.join_conditioner(Laplace, cparams, conditioner)\n(0.0, 1.0)\n\njulia> Laplace(params...) == Laplace(0.0, 1.0)\ntrue\n\nSee also: ExponentialFamily.separate_conditioner\n\n\n\n\n\n","category":"function"},{"location":"interface/","page":"Interface","title":"Interface","text":"For example, Laplace distribution defines the functions in the following way","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"# `params` are coming from the `Distribution.params(::Laplace)` and return (location, scale)\n# The `location`, however is a fixed parameter in the exponential distribution representation of Laplace\n# Hence, we return a tuple of tuple of actual parameter and the conditioner\nfunction separate_conditioner(::Type{Laplace}, params)\n location, scale = params\n return ((scale, ), location)\nend\n\n# The `join_conditioner` must join the actual parameters and the conditioner in such a way, that it is compatible \n# with the `Laplace` structure from the `Distributions.jl`. In Laplace, the location parameter goes first.\nfunction join_conditioner(::Type{Laplace}, cparams, conditioner) \n (scale, ) = cparams\n location = conditioner\n return (location, scale)\nend","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"In general, all functions defined for the ExponentialFamilyDistribution, such as getlogpartition or getbasemeasure accept an optional conditioner parameter, which is assumed to be nothing. Conditioned distribution implement the \"conditioned\" versions of such functions by explicitly requiring the conditioner parameter, e.g.","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"getsufficientstatistics(Laplace, 1.0) # explicit `conditioner = 1.0`","category":"page"},{"location":"interface/#Efficient-packing-of-the-natural-parameters-into-a-vectorized-form","page":"Interface","title":"Efficient packing of the natural parameters into a vectorized form","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"The ExponentialFamilyDistribution type stores its natural parameters in a vectorized, or packed, format. This is done for the sake of efficiency and to enhance compatibility with autodiff packages like ForwardDiff, which anticipate a single parameter vector. As a result, the tuple of natural parameters needs to be converted to its corresponding vectorized form and vice versa. To achieve this, the package provides the flatten_parameters, pack_parameters and unpack_parameters functions.","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"ExponentialFamily.flatten_parameters\nExponentialFamily.pack_parameters\nExponentialFamily.unpack_parameters","category":"page"},{"location":"interface/#ExponentialFamily.flatten_parameters","page":"Interface","title":"ExponentialFamily.flatten_parameters","text":"flatten_parameters(::Type{T}, params::Tuple)\n\nThis function returns the parameters of a distribution of type T in a flattened form without actually allocating the container.\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.pack_parameters","page":"Interface","title":"ExponentialFamily.pack_parameters","text":"pack_parameters([ space ], ::Type{T}, params::Tuple)\n\nThis function returns the parameters of a distribution of type T in a vectorized (packed) form. For most of the distributions the packed versions are of the same structure in any parameters space. For some distributions, however, it is necessary to indicate the space of the packaged parameters.\n\njulia> ExponentialFamily.pack_parameters((1, [2.0, 3.0], [4.0 5.0 6.0; 7.0 8.0 9.0]))\n9-element Vector{Float64}:\n 1.0\n 2.0\n 3.0\n 4.0\n 7.0\n 5.0\n 8.0\n 6.0\n 9.0\n\n\n\n\n\n","category":"function"},{"location":"interface/#ExponentialFamily.unpack_parameters","page":"Interface","title":"ExponentialFamily.unpack_parameters","text":"unpack_parameters([ space ], ::Type{T}, parameters)\n\nThis function \"unpack\" the vectorized form of the parameters in a tuple. For most of the distributions the packed parameters are of the same structure in any parameters space. For some distributions, however, it is necessary to indicate the space of the packaged parameters.\n\nSee also: MeanParametersSpace, NaturalParametersSpace\n\n\n\n\n\n","category":"function"},{"location":"interface/","page":"Interface","title":"Interface","text":"These functions are not exported by default, but it's important to note that the ExponentialFamilyDistributions type doesn't actually store the parameter tuple internally. Instead, the getnaturalparameters function returns the corresponding vectorized (packed) form of the natural parameters. In general, only the ExponentialFamily.unpack_parameters function must be implemented, as others could be implemented in a generic way.","category":"page"},{"location":"interface/#Attributes-of-the-exponential-family-distribution-based-on-Distribution","page":"Interface","title":"Attributes of the exponential family distribution based on Distribution","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"The ExponentialFamilyDistribution{T} where { T <: Distribution } type encompasses all fundamental attributes of the exponential family, including basemeasure, logpartition, sufficientstatistics, and fisherinformation. Furthermore, it's possible to retrieve the actual functions that compute these attributes. For instance, consider the following example:","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"basemeasure_of_bernoilli = getbasemeasure(Bernoulli)\n\nbasemeasure_of_bernoilli(0)","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"isproper(::Type{T}, parameters, conditioner) where {T <: Distribution}\ngetbasemeasure(::Type{T}, ::Nothing) where {T <: Distribution}\ngetsufficientstatistics(::Type{T}, ::Nothing) where { T <: Distribution }\ngetlogpartition(::Type{T}, _) where { T <: Distribution }\ngetfisherinformation(::Type{T}, _) where { T <: Distribution }","category":"page"},{"location":"interface/#ExponentialFamily.isproper-Union{Tuple{T}, Tuple{Type{T}, Any, Any}} where T<:Distribution","page":"Interface","title":"ExponentialFamily.isproper","text":"isproper([ space = NaturalParametersSpace() ], ::Type{T}, parameters, conditioner = nothing) where { T <: Distribution }\n\nA specific verion of isproper defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.\n\nSee also: NaturalParametersSpace, MeanParametersSpace\n\n\n\n\n\n","category":"method"},{"location":"interface/#ExponentialFamily.getbasemeasure-Union{Tuple{T}, Tuple{Type{T}, Nothing}} where T<:Distribution","page":"Interface","title":"ExponentialFamily.getbasemeasure","text":"getbasemeasure(::Type{<:Distribution}, [ conditioner ])\n\nA specific verion of getbasemeasure defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. For conditional exponential family distributions requires an extra conditioner argument.\n\n\n\n\n\n","category":"method"},{"location":"interface/#ExponentialFamily.getsufficientstatistics-Union{Tuple{T}, Tuple{Type{T}, Nothing}} where T<:Distribution","page":"Interface","title":"ExponentialFamily.getsufficientstatistics","text":"getsufficientstatistics(::Type{<:Distribution}, [ conditioner ])\n\nA specific verion of getsufficientstatistics defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. For conditional exponential family distributions requires an extra conditioner argument.\n\n\n\n\n\n","category":"method"},{"location":"interface/#ExponentialFamily.getlogpartition-Union{Tuple{T}, Tuple{Type{T}, Any}} where T<:Distribution","page":"Interface","title":"ExponentialFamily.getlogpartition","text":"getlogpartition([ space = NaturalParametersSpace() ], ::Type{T}, [ conditioner ]) where { T <: Distribution }\n\nA specific verion of getlogpartition defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.\n\nSee also: NaturalParametersSpace, MeanParametersSpace\n\n\n\n\n\n","category":"method"},{"location":"interface/#ExponentialFamily.getfisherinformation-Union{Tuple{T}, Tuple{Type{T}, Any}} where T<:Distribution","page":"Interface","title":"ExponentialFamily.getfisherinformation","text":"getfisherinformation([ space = NaturalParametersSpace() ], ::Type{T}) where { T <: Distribution }\n\nA specific verion of getfisherinformation defined particularly for distribution types from Distributions.jl package. Does not require an instance of the ExponentialFamilyDistribution and can be called directly with a specific distribution type instead. Optionally, accepts the space parameter, which defines the parameters space. For conditional exponential family distributions requires an extra conditioner argument.\n\nSee also: NaturalParametersSpace, MeanParametersSpace\n\n\n\n\n\n","category":"method"},{"location":"interface/","page":"Interface","title":"Interface","text":"Certain functions require knowledge about which parameter space is being used. By default, the NaturalParametersSpace is assumed.","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"getlogpartition(Bernoulli) === getlogpartition(NaturalParametersSpace(), Bernoulli)","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"NaturalParametersSpace\nMeanParametersSpace","category":"page"},{"location":"interface/#ExponentialFamily.NaturalParametersSpace","page":"Interface","title":"ExponentialFamily.NaturalParametersSpace","text":"NaturalParametersSpace\n\nSpecifies the natural parameters space η as the desired parameters space. Some functions (such as logpartition or fisherinformation) accept an additional space parameter to disambiguate the desired parameters space. Use map(NaturalParametersSpace() => MeanParametersSpace(), T, parameters, conditioner) to map the parameters and the conditioner of a distribution of type T from the natural parametrization to the corresponding mean parametrization.\n\nSee also: MeanParametersSpace, getmapping, NaturalToMean, MeanToNatural\n\n\n\n\n\n","category":"type"},{"location":"interface/#ExponentialFamily.MeanParametersSpace","page":"Interface","title":"ExponentialFamily.MeanParametersSpace","text":"MeanParametersSpace\n\nSpecifies the mean parameters space θ as the desired parameters space. Some functions (such as logpartition or fisherinformation) accept an additional space parameter to disambiguate the desired parameters space. Use map(MeanParametersSpace() => NaturalParametersSpace(), T, parameters, conditioner) to map the parameters and the conditioner of a distribution of type T from the mean parametrization to the corresponding natural parametrization.\n\nSee also: NaturalParametersSpace, getmapping, NaturalToMean, MeanToNatural\n\n\n\n\n\n","category":"type"},{"location":"interface/","page":"Interface","title":"Interface","text":"The isbasemeasureconstant function is defined for all supported distributions as well.","category":"page"},{"location":"interface/","page":"Interface","title":"Interface","text":"isbasemeasureconstant(Bernoulli)","category":"page"},{"location":"interface/#Extra-defined-distributions","page":"Interface","title":"Extra defined distributions","text":"","category":"section"},{"location":"interface/","page":"Interface","title":"Interface","text":"The package defines a list of extra distributions for a purpose of more efficiency in different circumstances. The list is available here.","category":"page"},{"location":"library/#library","page":"Library","title":"Library API","text":"","category":"section"},{"location":"library/#library-list-distributions-extra","page":"Library","title":"Additional distributions","text":"","category":"section"},{"location":"library/","page":"Library","title":"Library","text":"These are the distributions that are not included in the Distributions.jl package.","category":"page"},{"location":"library/","page":"Library","title":"Library","text":"ExponentialFamily.MatrixDirichlet\nExponentialFamily.GammaShapeRate\nExponentialFamily.GammaShapeScale\nExponentialFamily.NormalMeanPrecision\nExponentialFamily.NormalMeanVariance\nExponentialFamily.NormalWeightedMeanPrecision\nExponentialFamily.MvNormalMeanPrecision\nExponentialFamily.MvNormalMeanCovariance\nExponentialFamily.MvNormalWeightedMeanPrecision\nExponentialFamily.JointNormal\nExponentialFamily.JointGaussian\nExponentialFamily.WishartFast\nExponentialFamily.InverseWishartFast\nExponentialFamily.NormalGamma\nExponentialFamily.MvNormalWishart","category":"page"},{"location":"library/#ExponentialFamily.MatrixDirichlet","page":"Library","title":"ExponentialFamily.MatrixDirichlet","text":"MatrixDirichlet{T <: Real, A <: AbstractMatrix{T}} <: ContinuousMatrixDistribution\n\nA matrix-valued MatrixDirichlet distribution, where T is the element type of the matrix A. The a field stores the matrix parameter of the distribution.\n\nFields\n\na::A: The matrix parameter of the MatrixDirichlet distribution.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.GammaShapeRate","page":"Library","title":"ExponentialFamily.GammaShapeRate","text":"GammaShapeRate{T <: Real}\n\nA univariate gamma distribution parametrized by its shape a and rate b.\n\nFields\n\na: The shape parameter of the gamma distribution. It should be a positive real number.\nb: The rate parameter of the gamma distribution. It should be a positive real number.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.GammaShapeScale","page":"Library","title":"ExponentialFamily.GammaShapeScale","text":"GammaShapeScale{T}\n\nA continuous univariate gamma distribution parametrized by its shape α and scale β parameters.\n\nFields\n\nα: The shape parameter of the gamma distribution. It should be a positive real number.\nβ: The scale parameter of the gamma distribution. It should be a positive real number.\n\nNote\n\nGammaShapeScale is an alias for Gamma from Distributions.jl.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.NormalMeanPrecision","page":"Library","title":"ExponentialFamily.NormalMeanPrecision","text":"NormalMeanPrecision{T <: Real} <: ContinuousUnivariateDistribution\n\nA normal distribution with a known mean μ and precision w.\n\nFields\n\nμ::T: The mean of the normal distribution.\nw::T: The precision of the normal distribution.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.NormalMeanVariance","page":"Library","title":"ExponentialFamily.NormalMeanVariance","text":"NormalMeanVariance{T <: Real} <: ContinuousUnivariateDistribution\n\nA normal distribution with a known mean μ and variance v.\n\nFields\n\nμ::T: The mean of the normal distribution.\nv::T: The variance of the normal distribution.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.NormalWeightedMeanPrecision","page":"Library","title":"ExponentialFamily.NormalWeightedMeanPrecision","text":"NormalWeightedMeanPrecision{T <: Real} <: ContinuousUnivariateDistribution\n\nA normal distribution parametrized by its natural parameters: the weighted mean xi and precision w.\n\nFields\n\nxi::T: The weighted mean of the normal distribution. xi is computed as w * μ, where μ is the mean of the distribution.\nw::T: The precision (inverse variance) of the normal distribution.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.MvNormalMeanPrecision","page":"Library","title":"ExponentialFamily.MvNormalMeanPrecision","text":"MvNormalMeanPrecision{T <: Real, M <: AbstractVector{T}, P <: AbstractMatrix{T}} <: AbstractMvNormal\n\nA multivariate normal distribution with mean μ and precision matrix Λ, where T is the element type of the vectors M and matrices P.\n\nFields\n\nμ::M: The mean vector of the multivariate normal distribution.\nΛ::P: The precision matrix (inverse of the covariance matrix) of the multivariate normal distribution.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.MvNormalMeanCovariance","page":"Library","title":"ExponentialFamily.MvNormalMeanCovariance","text":"MvNormalMeanCovariance{T <: Real, M <: AbstractVector{T}, P <: AbstractMatrix{T}} <: AbstractMvNormal\n\nA multivariate normal distribution with mean μ and covariance matrix Σ, where T is the element type of the vectors M and matrices P.\n\nFields\n\nμ::M: The mean vector of the multivariate normal distribution.\nΣ::P: The covariance matrix of the multivariate normal distribution\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.MvNormalWeightedMeanPrecision","page":"Library","title":"ExponentialFamily.MvNormalWeightedMeanPrecision","text":"MvNormalWeightedMeanPrecision{T <: Real, M <: AbstractVector{T}, P <: AbstractMatrix{T}} <: AbstractMvNormal\n\nA multivariate normal distribution with a weighted mean vector xi and precision matrix Λ, where T is the element type of the vectors M and matrices P. This struct represents a natural parametrization of a multivariate Gaussian distribution.\n\nFields\n\nxi::M: The weighted mean vector of the multivariate normal distribution.\nΛ::P: The precision matrix (inverse of the covariance matrix) of the multivariate normal distribution.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.JointNormal","page":"Library","title":"ExponentialFamily.JointNormal","text":"JointNormal{D, S}\n\nJointNormal is an auxilary structure used for the joint marginal over Normally distributed variables. JointNormal stores a vector with the original dimensionalities (ds), so statistics can later be re-separated.\n\nUse ExponentialFamily.getcomponent(joint, index) to get a specific component of the joint distribution.\n\nFields\n\ndist: joint distribution (typically just a big MvNormal distribution, but maybe a tuple of individual means and covariance matrices)\nds: a tuple with the original dimensionalities of individual Normal distributions\nds[k] = (n,) where n is an integer indicates Multivariate normal of size n\nds[k] = () indicates Univariate normal\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.JointGaussian","page":"Library","title":"ExponentialFamily.JointGaussian","text":"An alias for the JointNormal.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.WishartFast","page":"Library","title":"ExponentialFamily.WishartFast","text":"WishartFast{T <: Real, A <: AbstractMatrix{T}} <: ContinuousMatrixDistribution\n\nThe WishartFast struct represents a fast version of the Wishart distribution. It is similar to the Wishart distribution from Distributions.jl, but it does not check input arguments, allowing the creation of improper Wishart messages.\n\nFor model creation and regular usage, it is recommended to use Wishart from Distributions.jl. The WishartFast distribution is intended for internal purposes and should not be directly used by regular users.\n\nFields\n\nν::T: The degrees of freedom parameter of the Wishart distribution.\ninvS::A: The inverse scale matrix parameter of the Wishart distribution.\n\nNote\n\nInternally, WishartFast stores and creates the inverse of its scale matrix. However, the params() function returns the scale matrix itself for backward compatibility. This is done to ensure better stability in the message passing update rules for ReactiveMP.jl.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.InverseWishartFast","page":"Library","title":"ExponentialFamily.InverseWishartFast","text":"InverseWishartFast{T <: Real, A <: AbstractMatrix{T}} <: ContinuousMatrixDistribution\n\nThe InverseWishartFast struct represents an improper Inverse Wishart distribution. It is similar to the InverseWishart distribution from Distributions.jl, but it does not check input arguments, allowing the creation of improper InverseWishart messages. \n\nFor model creation and regular usage, it is recommended to use InverseWishart from Distributions.jl. The InverseWishartFast distribution is intended for internal purposes and should not be directly used by regular users.\n\nFields\n\nν::T: The degrees of freedom parameter of the inverse Wishart distribution.\nS::A: The scale matrix parameter of the inverse Wishart distribution.\n\nNote\n\nThe InverseWishartFast distribution does not enforce input argument validation, making it suitable for specialized cases where improper message constructions are needed.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.NormalGamma","page":"Library","title":"ExponentialFamily.NormalGamma","text":"NormalGamma{T <: Real} <: ContinuousMultivariateDistribution\n\nA normal-gamma distribution, where T is a real number. This distribution is a joint distribution of a normal random variable with mean μ and precision λ, and a gamma-distributed random variable with shape α and rate β.\n\nFields\n\nμ::T: The mean of the normal distribution.\nλ::T: The precision of the normal distribution.\nα::T: The shape parameter of the gamma distribution.\nβ::T: The rate parameter of the gamma distribution.\n\n\n\n\n\n","category":"type"},{"location":"library/#ExponentialFamily.MvNormalWishart","page":"Library","title":"ExponentialFamily.MvNormalWishart","text":"MvNormalWishart{T, M <: AbstractArray{T}, V <: AbstractMatrix{T}, K <: Real, N <: Real} <: ContinuousMatrixDistribution\n\nA multivariate normal-Wishart distribution, where T is the element type of the arrays M and matrices V, and K and N are real numbers. This distribution is a joint distribution of a multivariate normal random variable with mean μ and a Wishart-distributed random matrix with scale matrix Ψ, degrees of freedom ν, and the scalar κ as a scaling parameter.\n\nFields\n\nμ::M: The mean vector of the multivariate normal distribution.\nΨ::V: The scale matrix of the Wishart distribution.\nκ::K: The scaling parameter of the Wishart distribution.\nν::N: The degrees of freedom of the Wishart distribution\n\n\n\n\n\n","category":"type"},{"location":"examples/#examples","page":"Examples","title":"Examples","text":"","category":"section"},{"location":"examples/#examples-product","page":"Examples","title":"Product of two probability distributions over the same variable","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"In this example, we'll show you how to use the ExponentialFamily package to calculate the product of probability distributions that both relate to the same variable \"X\". This operation results in another probability distribution, also centered around the variable \"X\". It's essential to note that this is distinct from multiplying probability distributions for two different variables, such as \"X\" and \"Y\", which yields a joint probability distribution. Calculating the product of two probability distributions over the same variable is a crucial step in applying Bayes' rule.","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"p(Xvert D) propto underbracep(X)p(DX)_mathrmproductoftwodistributions","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"To perform this operation, the ExponentialFamily library employs the prod function. This function takes a product strategy as its first argument. For instance:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"using ExponentialFamily, Distributions, BayesBase\n\nprior = Bernoulli(0.5)\nlikelihood = Bernoulli(0.6)\n\nposterior = prod(PreserveTypeProd(Distribution), prior, likelihood)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"You can achieve the same result in the general exponential family form, which operates within the natural parameter space:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"\nef_prior = convert(ExponentialFamilyDistribution, prior)\nef_likelihood = convert(ExponentialFamilyDistribution, likelihood)\n\nef_posterior = prod(PreserveTypeProd(ExponentialFamilyDistribution), ef_prior, ef_likelihood)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"Or even more concisely:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"prod(PreserveTypeProd(ExponentialFamilyDistribution), prior, likelihood)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"In this example, multiplying two Bernoulli distributions will always result in another Bernoulli distribution. However, this is not the case for all distributions. For instance, the product of two Laplace distributions may not yield another Laplace distribution, and representing the result in the same form might not be possible. In such cases, it's advisable to calculate the result within the exponential family domain. This is because the product of two exponential family distributions can always be represented as another exponential family distribution, as shown here:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"\nprior = Laplace(2.0, 3.0)\nlikelihood = Laplace(1.0, 4.0)\n\nprod(PreserveTypeProd(ExponentialFamilyDistribution), prior, likelihood)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"Note that the result does not correspond to the Laplace distribution and returns a generic univariate ExponentialFamilyDistribution. This approach ensures consistency and compatibility, especially when dealing with a wide range of probability distributions. Refer to the BayesBase for the documentation about available product strategies.","category":"page"},{"location":"examples/#Computing-various-useful-attributes-of-an-exponential-family-member","page":"Examples","title":"Computing various useful attributes of an exponential family member","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"The package implements attributes of many well known exponential family members, which are defined in this table. The attributes include getbasemeasure, getsufficientstatistics, getlogpartition, getfisherinformation, and others. In general, the interface for these functions assumes a family member \"tag,\" such as Normal or Bernoulli. Here are some examples of how to use these attributes:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"using ExponentialFamily, Distributions\n\n# Returns a function\nbasemeasure_of_normal = getbasemeasure(Normal)\n\nbasemeasure_of_normal(0.0)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"\n# Returns an iterable of functions\nsufficientstatistics_of_gamma = getsufficientstatistics(Gamma)\n\nmap(f -> f(1.0), sufficientstatistics_of_gamma)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"Some distributions, like the Laplace distribution, qualify as exponential family members only under certain conditions or when specific information is known in advance. In such cases, the ExponentialFamily package introduces the concept of a conditioner. For instance, the Laplace distribution becomes a member of the exponential family only when the location parameter is known and fixed. Consequently, we condition on the location parameter:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"laplace = Laplace(2.0, 1.0)\n\ncanonical = convert(ExponentialFamilyDistribution, laplace)\n\ngetconditioner(canonical)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"# For conditioned distributions, the `conditioner` must be present as a second argument\nbasemeasure_of_laplace = getbasemeasure(Laplace, 2.0)\n\nbasemeasure_of_laplace(1.0)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"The getlogpartition and getfisherinformation functions optionally accept a space parameter as the first argument. This space parameter specifies the parameterization space, such as MeanParametersSpace or [NaturalParametersSpace]. The result obtained from these functions (in general) depends on the chosen parameter space:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"logpartition_of_gamma_in_mean_space = getlogpartition(MeanParametersSpace(), Gamma)\n\ngamma_parameters_in_mean_space = [ 1.0, 2.0 ]\n\nlogpartition_of_gamma_in_mean_space(gamma_parameters_in_mean_space)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"logparition_of_gamma_in_natural_space = getlogpartition(NaturalParametersSpace(), Gamma)\n\ngamma_parameters_in_natural_space = map(\n MeanParametersSpace() => NaturalParametersSpace(), \n Gamma,\n gamma_parameters_in_mean_space\n)\n\nlogparition_of_gamma_in_natural_space(gamma_parameters_in_natural_space)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"The same principle applies to the Fisher information matrix:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"fisherinformation_of_gamma_in_mean_space = getfisherinformation(MeanParametersSpace(), Gamma)\n\nfisherinformation_of_gamma_in_mean_space(gamma_parameters_in_mean_space)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"fisherinformation_of_gamma_in_natural_space = getfisherinformation(NaturalParametersSpace(), Gamma)\n\nfisherinformation_of_gamma_in_natural_space(gamma_parameters_in_natural_space)","category":"page"},{"location":"examples/#Approximating-attributes","page":"Examples","title":"Approximating attributes","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"Refer to the ExpectationApproximations.jl package for approximating various attributes of the members of the exponential family.","category":"page"},{"location":"#ExponentialFamily.jl","page":"Home","title":"ExponentialFamily.jl","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Julia package that extends the functionality of Distributions.jl by providing a collection of exponential family distributions and customized implementations. It is designed to facilitate working with exponential family distributions and offers specialized functionality tailored to this class of distributions.","category":"page"},{"location":"#Core-Principles","page":"Home","title":"Core Principles","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"The package is built around several core principles:","category":"page"},{"location":"","page":"Home","title":"Home","text":"High performance with minimal allocations, striving for complete type stability.\nCompatibility with distributions defined in Distributions.jl.\nEase of use and rich functionality.","category":"page"},{"location":"#Table-of-Contents","page":"Home","title":"Table of Contents","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Interface\nExamples\nLibrary","category":"page"},{"location":"#Index","page":"Home","title":"Index","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"","category":"page"}] }