From bded781d6c85724a75aa53977da442a790dd3fb0 Mon Sep 17 00:00:00 2001 From: "Documenter.jl" Date: Tue, 3 Oct 2023 13:28:38 +0000 Subject: [PATCH] build based on 6ade566 --- dev/.documenter-siteinfo.json | 2 +- dev/examples/index.html | 2 +- dev/index.html | 2 +- dev/interface/index.html | 22 +++++++++++----------- dev/library/index.html | 10 +++++----- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 44249df0..744a1c67 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.9.3","generation_timestamp":"2023-10-03T13:06:01","documenter_version":"1.1.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.9.3","generation_timestamp":"2023-10-03T13:28:34","documenter_version":"1.1.0"}} \ No newline at end of file diff --git a/dev/examples/index.html b/dev/examples/index.html index d8bcdb83..a60440ea 100644 --- a/dev/examples/index.html +++ b/dev/examples/index.html @@ -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 af603961..4bb15f2c 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 a74def56..0b3eea68 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"#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]))
 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 9e86f9eb..30ba8b3e 100644 --- a/dev/library/index.html +++ b/dev/library/index.html @@ -11,19 +11,19 @@ ExponentialFamily(NormalMeanVariance) julia> mean(product), var(product) -(0.0, 0.5)

See also: default_prod_rule, ClosedProd, PreserveTypeProd, GenericProd

source
ExponentialFamily.default_prod_ruleFunction
default_prod_rule(::Type, ::Type)

Returns the most suitable prod rule for two given distribution types. Returns UnspecifiedProd by default.

See also: prod, ClosedProd, 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.UnspecifiedProdType
UnspecifiedProd

A strategy for the prod function, which does not compute the prod, but instead fails in run-time and prints a descriptive error message.

See also: prod, ClosedProd, GenericProd

source
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))
+(0.0, 0.5)

See also: default_prod_rule, ClosedProd, PreserveTypeProd, GenericProd

source
ExponentialFamily.default_prod_ruleFunction
default_prod_rule(::Type, ::Type)

Returns the most suitable prod rule for two given distribution types. Returns UnspecifiedProd by default.

See also: prod, ClosedProd, 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.UnspecifiedProdType
UnspecifiedProd

A strategy for the prod function, which does not compute the prod, but instead fails in run-time and prints a descriptive error message.

See also: prod, ClosedProd, GenericProd

source
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.PreserveTypeLeftProdType
PreserveTypeLeftProd

An alias for the PreserveTypeProd(L) where L is the type of the left argument of the prod function.

julia> product = prod(PreserveTypeLeftProd(), NormalMeanVariance(-1.0, 1.0), NormalMeanPrecision(1.0, 1.0))
+(0.0, 0.5)

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

source
ExponentialFamily.PreserveTypeLeftProdType
PreserveTypeLeftProd

An alias for the PreserveTypeProd(L) where L is the type of the left argument of the prod function.

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

See also: prod, PreserveTypeProd, PreserveTypeRightProd, GenericProd

source
ExponentialFamily.PreserveTypeRightProdType
PreserveTypeRightProd

An alias for the PreserveTypeProd(R) where R is the type of the right argument of the prod function.

julia> product = prod(PreserveTypeRightProd(), NormalMeanVariance(-1.0, 1.0), NormalMeanPrecision(1.0, 1.0))
+(0.0, 0.5)

See also: prod, PreserveTypeProd, PreserveTypeRightProd, GenericProd

source
ExponentialFamily.PreserveTypeRightProdType
PreserveTypeRightProd

An alias for the PreserveTypeProd(R) where R is the type of the right argument of the prod function.

julia> product = prod(PreserveTypeRightProd(), NormalMeanVariance(-1.0, 1.0), NormalMeanPrecision(1.0, 1.0))
 NormalMeanPrecision{Float64}(μ=0.0, w=2.0)
 
 julia> mean(product), var(product)
-(0.0, 0.5)

See also: prod, PreserveTypeProd, PreserveTypeLeftProd, 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.JointGaussianType

An alias for the JointNormal.

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

ExponentialFamily.paramfloattypeFunction
paramfloattype(distribution)

Returns the underlying float type of distribution's parameters.

See also: ExponentialFamily.promote_paramfloattype, ExponentialFamily.convert_paramfloattype

source
ExponentialFamily.sampletypeFunction
sampletype(distribution)

Returns a type of the distribution. By default fallbacks to the eltype.

See also: ExponentialFamily.samplefloattype, ExponentialFamily.promote_sampletype, ExponentialFamily.promote_samplefloattype

source
ExponentialFamily.samplefloattypeFunction
samplefloattype(distribution)

Returns 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)).

See also: ExponentialFamily.sampletype, ExponentialFamily.promote_sampletype, ExponentialFamily.promote_samplefloattype

source
ExponentialFamily.promote_variate_typeFunction
promote_variate_PromoteTypeConverter(::Type{ <: VariateForm }, distribution_type)

Promotes (if possible) a distribution_type to be of the specified variate form.

source
ExponentialFamily.promote_paramfloattypeFunction
promote_paramfloattype(distributions...)

Promotes paramfloattype of the distributions to a single type. See also promote_type.

See also: ExponentialFamily.paramfloattype, ExponentialFamily.convert_paramfloattype

source
ExponentialFamily.promote_sampletypeFunction
promote_sampletype(distributions...)

Promotes sampletype of the distributions to a single type. See also promote_type.

See also: ExponentialFamily.sampletype, ExponentialFamily.samplefloattype, ExponentialFamily.promote_samplefloattype

source
ExponentialFamily.promote_samplefloattypeFunction
promote_samplefloattype(distributions...)

Promotes samplefloattype of the distributions to a single type. See also promote_type.

See also: ExponentialFamily.sampletype, ExponentialFamily.samplefloattype, ExponentialFamily.promote_sampletype

source
ExponentialFamily.convert_paramfloattypeFunction
convert_paramfloattype(::Type{T}, distribution)

Converts (if possible) the params float type of the distribution to be of type T.

See also: ExponentialFamily.paramfloattype, ExponentialFamily.promote_paramfloattype

source
convert_paramfloattype(::Type{T}, container)

Converts (if possible) the elements of the container to be of type T.

source

Extra stats functions

ExponentialFamily.mirrorlogFunction
mirrorlog(x)

Returns log(1 - x).

source
ExponentialFamily.xtlogFunction
xtlog(x)

Returns x * log(x).

source
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
ExponentialFamily.mvtrigammaFunction
mvtrigamma(p, x)

Computes multivariate trigamma function .

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)
+(0.0, 0.5)

See also: prod, PreserveTypeProd, PreserveTypeLeftProd, 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.JointGaussianType

An alias for the JointNormal.

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

ExponentialFamily.paramfloattypeFunction
paramfloattype(distribution)

Returns the underlying float type of distribution's parameters.

See also: ExponentialFamily.promote_paramfloattype, ExponentialFamily.convert_paramfloattype

source
ExponentialFamily.sampletypeFunction
sampletype(distribution)

Returns a type of the distribution. By default fallbacks to the eltype.

See also: ExponentialFamily.samplefloattype, ExponentialFamily.promote_sampletype, ExponentialFamily.promote_samplefloattype

source
ExponentialFamily.samplefloattypeFunction
samplefloattype(distribution)

Returns 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)).

See also: ExponentialFamily.sampletype, ExponentialFamily.promote_sampletype, ExponentialFamily.promote_samplefloattype

source
ExponentialFamily.promote_variate_typeFunction
promote_variate_PromoteTypeConverter(::Type{ <: VariateForm }, distribution_type)

Promotes (if possible) a distribution_type to be of the specified variate form.

source
ExponentialFamily.promote_paramfloattypeFunction
promote_paramfloattype(distributions...)

Promotes paramfloattype of the distributions to a single type. See also promote_type.

See also: ExponentialFamily.paramfloattype, ExponentialFamily.convert_paramfloattype

source
ExponentialFamily.promote_sampletypeFunction
promote_sampletype(distributions...)

Promotes sampletype of the distributions to a single type. See also promote_type.

See also: ExponentialFamily.sampletype, ExponentialFamily.samplefloattype, ExponentialFamily.promote_samplefloattype

source
ExponentialFamily.promote_samplefloattypeFunction
promote_samplefloattype(distributions...)

Promotes samplefloattype of the distributions to a single type. See also promote_type.

See also: ExponentialFamily.sampletype, ExponentialFamily.samplefloattype, ExponentialFamily.promote_sampletype

source
ExponentialFamily.convert_paramfloattypeFunction
convert_paramfloattype(::Type{T}, distribution)

Converts (if possible) the params float type of the distribution to be of type T.

See also: ExponentialFamily.paramfloattype, ExponentialFamily.promote_paramfloattype

source
convert_paramfloattype(::Type{T}, container)

Converts (if possible) the elements of the container to be of type T.

source

Extra stats functions

ExponentialFamily.mirrorlogFunction
mirrorlog(x)

Returns log(1 - x).

source
ExponentialFamily.xtlogFunction
xtlog(x)

Returns x * log(x).

source
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
ExponentialFamily.mvtrigammaFunction
mvtrigamma(p, x)

Computes multivariate trigamma function .

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]
@@ -41,4 +41,4 @@
 μ: [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
+)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