gaussian_toolbox package#
Subpackages#
Submodules#
gaussian_toolbox.approximate_conditional module#
- class LConjugateFactorMGaussianConditional(*, M, b=None, Sigma=None, Lambda=None, ln_det_Sigma=None)#
Bases:
ConditionalGaussianPDF
,Mapping
Base class for approximate conditional.
- evaluate_phi(x)#
Evaluate the feature vector
\[\phi(X=x) = (x_0, x_1,...,x_m, k(h_1(x))),...,k(h_n(x)))^\top.\]- Parameters:
x (
Float[Array, 'N Dx']
) – Points where phi should be evaluated.- Return type:
Float[Array, 'N Dphi']
- Returns:
Feature vector.
- get_conditional_mu(x, **kwargs)#
Compute the conditional mu function \(\mu(X=x) = M \phi(x) + b\).
- Parameters:
x (
Float[Array, 'N Dx']
) – Points where \(\phi\) should be evaluated.- Return type:
Float[Array, '1 N Dy']
- Returns:
Conditional mu.
- set_y(y, **kwargs)#
Not valid function for this model class.
- Parameters:
y (
Float[Array, 'R Dy']
) – Data for \(Y\), where the rth entry is associated with the rth conditional density.- Raises:
AttributeError – Raised because doesn’t \(p(Y|X)\) is not a ConjugateFactor for \(X\).
- get_expected_moments(p_x)#
Compute the expected covariance \(\Sigma_Y = \mathbb{E}[YY^\top] - \mathbb{E}[Y]\mathbb{E}[Y]^\top\).
- Parameters:
p_x (
GaussianPDF
) – The density which we average over.- Return type:
Tuple
[Float[Array, 'R Dy']
,Float[Array, 'R Dy Dy']
]- Returns:
Returns the expected mean and covariance.
- get_expected_cross_terms(p_x)#
Compute \(\mathbb{E}[YX^\top] = \int\int YX^\top p(Y|X)p(X) {\rm d}Y{\rm d}x = \int (M f(X) + b)X^\top p(X) {\rm d}X\).
- Parameters:
p_x (
GaussianPDF
) – The density which we average over.- Return type:
Float[Array, 'R Dx Dy']
- Returns:
Returns the cross expectations.
- affine_joint_transformation(p_x, **kwargs)#
Get an approximation of the joint density
The mean is given by
\[\mu_{XY} = (\mu_X, \mu_Y)^\top\]with \(\mu_Y = \mathbb{E}[\mu_Y(X)]\). The covariance is given by
\[\begin{split}\Sigma_{xy} = \begin{pmatrix} \Sigma_X & \mathbb{E}[XY^\top] - \mu_X\mu_Y^\top \\ \mathbb{E}[YX^\top] - \mu_Y\mu_X^\top & \mathbb{E}[YY^\top] - \mu_Y\mu_Y^\top \end{pmatrix}.\end{split}\]- Parameters:
p_x (
GaussianPDF
) – The density which we average over.- Return type:
- Returns:
The joint distribution p(x,y).
- affine_conditional_transformation(p_x, **kwargs)#
Get an approximation of the joint density via moment matching
\[p(X|Y) \approx {\cal N}(\mu_{X|Y},Sigma_{X|Y}),\]- Parameters:
p_x (
GaussianPDF
) – The density which we average over.- Returns:
\(p(X|Y)\).
- Return type:
The conditional density
- affine_marginal_transformation(p_x, **kwargs)#
Get an approximation of the marginal density
\[p(Y)\aprox N(\mu_Y,\Sigma_y),\]The mean is given by
\[\mu_Y = \mathbb{E}[\mu_Y(X)].\]The covariance is given by
\[\Sigma_Y = \mathbb{E}[YY^\top] - \mu_Y\mu_Y^\top.\]- Parameters:
p_x (
GaussianPDF
) – The density which we average over.- Return type:
- Returns:
The joint distribution p(y).
- integrate_log_conditional(p_yx, **kwargs)#
Integrates over the log conditional with respect to the pdf \(p(Y,X)\). I.e.
\[\int \log(p(Y|X))p(Y,X){\rm d}Y{\rm d}X.\]- Parameters:
p_yx (
GaussianMeasure
) – Probability density function (first dimensions are \(Y\), last ones are \(X\)).- Raises:
NotImplementedError – Only implemented for R=1.
- Return type:
Float[Array, 'R']
- Returns:
Returns the integral with respect to density \(p(Y,X)\).
- integrate_log_conditional_y(p_x, **kwargs)#
Computes the expectation over the log conditional, but just over \(X\). I.e. it returns
\[f(Y) = \int \log(p(Y|X))p(X){\rm d}x.\]- Parameters:
p_x (
GaussianMeasure
) – Density over \(X\).- Raises:
NotImplementedError – Only implemented for R=1.
- Return type:
callable
- Returns:
The integral as function of \(Y\).
- class LRBFGaussianConditional(*, M, b=None, Sigma=None, Lambda=None, ln_det_Sigma=None, mu, length_scale)#
Bases:
LConjugateFactorMGaussianConditional
,Mapping
A conditional Gaussian density, with a linear RBF mean (LRBFM) function,
\[p(Y|X) = {\cal N}(\mu(X), \Sigma)\]with the conditional mean function \(\mu(X) = M \phi(X) + b\). \(\phi(X)\) is a feature vector of the form
\[\phi(X) = (1,X_1,...,X_m,k(h_1(X)),...,k(h_n(X)))^\top,\]with
\[k(h) = \exp(-h^2 / 2) \text{ and } h_i(X) = (X_i - s_{i}) / l_i.\]Note, that the affine transformations will be approximated via moment matching.
- Parameters:
M (
Float[Array, '1 Dy Dk+Dx']
) – Matrix in the mean function.b (
Optional
[Float[Array, '1 Dy']
]) – Vector in the conditional mean function.mu (
Float[Array, 'Dk Dx']
) – Parameters for linear mapping in the nonlinear functions.length_scale (
Float[Array, 'Dk Dx']
) – Length-scale of the kernels.Sigma (
Optional
[Float[Array, '1 Dy Dy']
]) – The covariance matrix of the conditional.Lambda (
Optional
[Float[Array, '1 Dy Dy']
]) – Information (precision) matrix of the Gaussians.ln_det_Sigma (
Optional
[Float[Array, '1']
]) – Log determinant of the covariance matrix.
- Raises:
RuntimeError – If neither Sigma nor Lambda are provided.
-
M:
Float[Array, '1 Dy Dk+Dx']
#
-
mu:
Float[Array, 'Dk Dx']
#
-
length_scale:
Float[Array, 'Dk Dx']
#
-
Sigma:
Float[Array, '1 Dy Dy']
= None#
-
Lambda:
Float[Array, '1 Dy Dy']
= None#
-
ln_det_Sigma:
Float[Array, '1']
= None#
- property Dk: int#
Number of kernels.
- property Dx: int#
Dimensionality of \(X\).
- property Dphi: int#
Dimensionality of feature vector (\(D_x+D_k\)).
- update_phi()#
Set up the non-linear kernel function in \(\phi(x)\).
- integrate_log_conditional(p_yx, p_x=None, **kwargs)#
Integrate over the log conditional with respect to the pdf \(p(Y,X)\). I.e.
\[\int \log(p(Y|X))p(Y,X){\rm d}Y{\rm d}X.\]- Parameters:
p_yx (
GaussianPDF
) – Probability density function (first dimensions are \(Y\), last ones are \(X\)).- Raises:
NotImplementedError – Only implemented for R=1.
- Return type:
Float[Array, 'R']
- Returns:
Returns the integral with respect to density \(p(Y,X)\).
- integrate_log_conditional_y(p_x, y=None, **kwargs)#
Compute the expectation over the log conditional, but just over \(X\). I.e. it returns
\[f(Y) = \int \log(p(Y|X))p(X){\rm d}X.\]- Parameters:
p_x (
GaussianPDF
) – Density over \(X\).- Raises:
NotImplementedError – Only implemented for R=1.
- Return type:
Union
[callable
,Float[Array, 'R Dy']
]- Returns:
callable
- class LSEMGaussianConditional(*, M, b=None, Sigma=None, Lambda=None, ln_det_Sigma=None, W)#
Bases:
LConjugateFactorMGaussianConditional
,Mapping
A conditional Gaussian density, with a linear squared exponential mean (LSEM) function,
\[p(Y|X) = {\cal N}(\mu(X), \Sigma)\]with the conditional mean function \(mu(X) = M \phi(X) + b\). \(\phi(X)\) is a feature vector of the form
\[\phi(X) = (1,X_1,...,X_m,k(h_1(X)),...,k(h_n(X)))^\top,\]with
\[k(h) = exp(-h^2 / 2) \text{ and } h_i(x) = w_i^\top x + w_{i,0}.\]Note, that the affine transformations will be approximated via moment matching.
- Parameters:
M (
Float[Array, '1 Dy Dk+Dx']
) – Matrix in the mean function.b (
Optional
[Float[Array, '1 Dy']
]) – Vector in the conditional mean function.W (
Float[Array, 'Dk Dx+1']
) – Parameters for linear mapping in the nonlinear functions.Sigma (
Optional
[Float[Array, '1 Dy Dy']
]) – The covariance matrix of the conditional.Lambda (
Optional
[Float[Array, '1 Dy Dy']
]) – Information (precision) matrix of the Gaussians.ln_det_Sigma (
Optional
[Float[Array, '1']
]) – Log determinant of the covariance matrix.
- Raises:
RuntimeError – If neither Sigma nor Lambda are provided.
-
M:
Float[Array, '1 Dy Dk+Dx']
#
-
W:
Float[Array, 'Dk Dx+1']
#
-
Sigma:
Float[Array, '1 Dy Dy']
= None#
-
Lambda:
Float[Array, '1 Dy Dy']
= None#
-
ln_det_Sigma:
Float[Array, '1']
= None#
- property Dk: int#
Number of kernels.
- property Dx: int#
Dimensionality of \(X\).
- property Dphi: int#
Dimensionality of feature vector (\(D_x+D_k\)).
- update_phi()#
Set up the non-linear kernel function in \(\phi(x)\).
- integrate_log_conditional(p_yx, p_x=None, **kwargs)#
Integrate over the log conditional with respect to the pdf \(p(Y,X)\). I.e.
\[\int \log(p(Y|X))p(Y,X){\rm d}Y{\rm d}X.\]- Parameters:
p_yx (
GaussianPDF
) – Probability density function (first dimensions are \(Y\), last ones are \(X\)).- Raises:
NotImplementedError – Only implemented for R=1.
- Return type:
Float[Array, 'R']
- Returns:
Returns the integral with respect to density \(p(Y,X)\).
- integrate_log_conditional_y(p_x, y=None, **kwargs)#
Compute the expectation over the log conditional, but just over \(X\). I.e. it returns
\[f(Y) = \int \log(p(Y|X))p(X){\rm d}X.\]- Parameters:
p_x (
GaussianPDF
) – Density over \(X\).- Raises:
NotImplementedError – Only implemented for R=1.
- Return type:
Union
[callable
,Float[Array, 'R']
]- Returns:
The integral as function of \(Y\). If provided already evaluated for \(Y=y\).
- class HeteroscedasticConditional(*, M, b=None, Sigma=None, A, W)#
Bases:
ConditionalGaussianPDF
,Mapping
A conditional Gaussian density, with a heteroscedastic covariance,
\[p(y|x) = N(\mu(x), \Sigma(x))\]with the conditional mean function \(\mu(x) = M x + b\). The covariance matrix has the form
\[\Sigma_y(x) = AA^\top + AD(x)A^\top.\]and \(D_i(x) = \exp(h_i(x))\) and \(h_i(x) = w_i^\top x + b_i\).
Note, that the affine transformations will be approximated via moment matching.
- Parameters:
M (
Float[Array, '1 Dy Dx']
) – Matrix in the mean function.b (
Optional
[Float[Array, '1 Dy']
]) – Vector in the conditional mean function.sigma_x – Diagonal noise parameter.
U – Othonormal vectors for low rank noise part.
W (
Float[Array, 'Dk Dx+1']
) – Noise weights for low rank components (w_i & b_i).beta – Scaling for low rank noise components.
- Raises:
NotImplementedError – Only works with R==1.
-
M:
Float[Array, '1 Dy Dx']
#
-
A:
Float[Array, '1 Dy Da']
#
-
W:
Float[Array, 'Dk Dx+1']
#
-
Sigma:
Float[Array, '1 Dy Dy']
= None#
- abstract link_function(h)#
Link function for the heteroscedastic noise.
- Return type:
']
- property R: int#
Number of conditionals (leading dimension).
- property Dy: int#
Dimensionality of \(Y\).
- property Dx: int#
Dimensionality of \(X\).
- property Da: int#
Number of orthonormal low rank vectors \(U\).
- property Dk: int#
Number of orthonormal low rank vectors \(U\).
- linear_layer(x)#
Linear layer of the argument of heteroscedastic link function.
- Return type:
Float[Array, 'N Dk']
- Returns:
\(w^ op x + w_0\).
- get_conditional_cov(x, invert=False)#
Evaluate the covariance at a given \(X=x\), i.e.
\[\Sigma_y(X=x) = \Sigma + A_{:k} D(x) A_{:k}^\top,\]with \(D_i(x) = \cosh(h_i(x))-1\) and \(h_i(x) = w_i^\top x + b_i\).
- Parameters:
x (
Float[Array, 'N Dx']
) – Instances, the \(\mu\) should be conditioned on.- Return type:
Union
[Float[Array, 'N Dy Dy']
,Tuple
[Float[Array, 'N Dy Dy']
,Float[Array, 'N Dy Dy']
,Float[Array, 'N']
]]- Returns:
Conditional covariance.
- condition_on_x(x, **kwargs)#
Get Gaussian Density conditioned on \(X=x\).
- Parameters:
x (
Float[Array, 'N Dx']
) – Instances, the mu and Sigma should be conditioned on.- Return type:
- Returns:
The density conditioned on \(X=x\).
- set_y(y, **kwargs)#
Not valid function for this model class.
- Parameters:
y (
Float[Array, 'R Dy']
) – Data for \(Y\), where the rth entry is associated with the rth conditional density.- Raises:
AttributeError – Raised because doesn’t \(p(Y|X)\) is not a ConjugateFactor for \(X\).
- integrate_Sigma_x(p_x)#
Integrate covariance with respect to \(p(X)\).
\[\int \Sigma_Y(X)p(X) {\rm d}X.\]- Parameters:
p_x (
GaussianPDF
) – The density the covatiance is integrated with.- Return type:
Float[Array, 'Dy Dy']
- Returns:
Integrated covariance matrix.
- get_expected_moments(p_x)#
Compute the expected mean and covariance
\[\mu_y = \mathbb{E}[y] = M \mathbb{E}[x] + b\]\[\Sigma_y = \mathbb{E}[yy'] - \mu_y \mu_y^\top = \sigma_x^2 I + \sum_i U_i \mathbb{E}[D_i(x)] U_i^\top + \mathbb{E}[\mu(x)\mu(x)^\top] - \mu_y \mu_y^\top\]- Parameters:
p_x (
GaussianPDF
) – The density which we average over.- Return type:
Tuple
[Float[Array, 'R Dy']
,Float[Array, '1 Dy Dy']
]- Returns:
Returns the expected mean and covariance.
- get_expected_cross_terms(p_x)#
Compute \(\mathbb{E}[yx^\top] = \int\int yx^\top p(y|x)p(x) {\rm d}y{\rm d}x = \int (M x + b)x^\top p(x) {\rm d}x\).
- Parameters:
p_x (
GaussianPDF
) – The density which we average over.- Return type:
Float[Array, 'R Dx Dy']
- Returns:
Cross expectations.
- affine_joint_transformation(p_x, **kwargs)#
Get an approximation of the joint density
\[p(x,y) ~= {\cal N}(\mu_{xy},\Sigma_{xy}),\]The mean is given by
\[\mu_{xy} = (\mu_x, \mu_y)^\top\]with \(\mu_y = \mathbb{E}[\mu_y(x)]\). The covariance is given by
\[\begin{split}\Sigma_{xy} = \begin{pmatrix} \Sigma_x & \mathbb{E}[xy^\top] - \mu_x\mu_y^\top \\ \mathbb{E}[yx^\top] - \mu_y\mu_x^\top & \mathbb{E}[yy^\top] - \mu_y\mu_y^\top \end{pmatrix}.\end{split}\]- Parameters:
p_x (
GaussianPDF
) – The density which we average over.- Return type:
- Returns:
Joint distribution of \(p(x,y)\).
- affine_conditional_transformation(p_x)#
Get an approximation of the joint density via moment matching
\[p(X|Y) \approx {\cal N}(\mu_{X|Y},\Sigma_{X|Y}).\]- Parameters:
p_x (
GaussianPDF
) – Marginal Gaussian density over \(X\).- Return type:
- Returns:
Conditional density of \(p(X|Y)\).
- affine_marginal_transformation(p_x, **kwargs)#
Get an approximation of the marginal density
The mean is given by
\[\mu_Y = \mathbb{E}[\mu_Y(X)].\]The covariance is given by
\[\Sigma_y = \mathbb{E}[YY^\top] - \mu_Y\mu_Y^\top.\]- Parameters:
p_x (
GaussianPDF
) – Marginal Gaussian density over :math`X`.- Return type:
- Returns:
The marginal density \(p(Y)\).
- integrate_log_conditional_y(p_x, y, **kwargs)#
Computes the expectation over the log conditional, but just over \(X\). I.e. it returns
\[f(Y) = \int \log(p(Y|X))p(X){\rm d}x.\]- Parameters:
p_x (
GaussianPDF
) – Density over \(X\).- Raises:
NotImplementedError – Only implemented for R=1.
- Return type:
Float[Array, 'N']
- Returns:
The integral as function of \(Y\).
- abstract k_func(p_x, W_i, omega_dagger)#
- Return type:
Float[Array, 'R']
- get_lb_log_det(p_x)#
- Return type:
Float[Array, 'N']
- get_lb_quadratic_term(p_x, y)#
- Return type:
Float[Array, 'N']
- get_lb_heteroscedastic_term_i(p_x, y, W_i, a_i)#
- Return type:
Float[Array, 'N']
- class HeteroscedasticExpConditional(*, M, b=None, Sigma=None, A, W)#
Bases:
HeteroscedasticConditional
,Mapping
-
M:
Float[Array, '1 Dy Dx']
#
-
A:
Float[Array, '1 Dy Da']
#
-
W:
Float[Array, 'Dk Dx+1']
#
-
Sigma:
Float[Array, '1 Dy Dy']
= None#
- link_function(h)#
Link function for the heteroscedastic noise.
- Return type:
']
- k_func(p_x, W_i, omega_dagger)#
- Return type:
Float[Array, 'R']
-
M:
- class HeteroscedasticCoshM1Conditional(*, M, b=None, Sigma=None, A, W)#
Bases:
HeteroscedasticConditional
,Mapping
-
M:
Float[Array, '1 Dy Dx']
#
-
A:
Float[Array, '1 Dy Da']
#
-
W:
Float[Array, 'Dk Dx+1']
#
-
Sigma:
Float[Array, '1 Dy Dy']
= None#
- link_function(h)#
Link function for the heteroscedastic noise.
- Return type:
']
- k_func(p_x, W_i, omega_dagger)#
- Return type:
Float[Array, 'R']
-
M:
- class HeteroscedasticHeavisideConditional(*, M, b=None, Sigma=None, A, W)#
Bases:
HeteroscedasticConditional
,Mapping
-
M:
Float[Array, '1 Dy Dx']
#
-
A:
Float[Array, '1 Dy Da']
#
-
W:
Float[Array, 'Dk Dx+1']
#
-
Sigma:
Float[Array, '1 Dy Dy']
= None#
- link_function(h)#
Link function for the heteroscedastic noise.
- Return type:
']
- get_lb_log_det(p_x)#
- Return type:
Float[Array, 'N']
- get_lb_heteroscedastic_term_i(p_x, y, W_i, a_i)#
- k_func(p_x, W_i, omega_dagger)#
- Return type:
Float[Array, 'R']
-
M:
- class HeteroscedasticReLUConditional(*, M, b=None, Sigma=None, A, W)#
Bases:
HeteroscedasticConditional
,Mapping
-
M:
Float[Array, '1 Dy Dx']
#
-
A:
Float[Array, '1 Dy Da']
#
-
W:
Float[Array, 'Dk Dx+1']
#
-
Sigma:
Float[Array, '1 Dy Dy']
= None#
- link_function(h)#
Link function for the heteroscedastic noise.
- Return type:
']
- k_func(p_x, W_i, omega_dagger)#
- Return type:
Float[Array, 'R']
-
M:
gaussian_toolbox.conditional module#
- class ConditionalGaussianPDF(*, M, b=None, Sigma=None, Lambda=None, ln_det_Sigma=None)#
Bases:
Mapping
A conditional Gaussian density
\[p(Y|X) = {\cal N}(\mu(X), \Sigma),\]with the conditional mean function \(\mu(X) = M X + b\).
- Parameters:
M (
Float[Array, 'R Dy Dx']
) – Matrix in the mean function.b (
Optional
[Float[Array, 'R Dy']
]) – Vector in the conditional mean function. If None all entries are zeros.Sigma (
Optional
[Float[Array, 'R Dy Dy']
]) – The covariance matrix of the conditional.Lambda (
Optional
[Float[Array, 'R Dy Dy']
]) – Information (precision) matrix of the Gaussians.ln_det_Sigma (
Optional
[Float[Array, 'R']
]) – Log determinant of the covariance matrix.
- Raises:
RuntimeError – Raised if neither Sigma nor Lambda are provided.
-
M:
Float[Array, 'R Dy Dx']
#
-
b:
Float[Array, 'R Dy']
= None#
-
Sigma:
Float[Array, 'R Dy Dy']
= None#
-
Lambda:
Float[Array, 'R Dy Dy']
= None#
-
ln_det_Sigma:
Float[Array, 'R']
= None#
- property R: int#
Number of conditionals (leading dimension).
- property Dy: int#
Dimensionality of \(Y\).
- property Dx: int#
Dimensionality of \(X\).
- slice(indices)#
Return the conditional with only the specified entries.
- Parameters:
indices (
Int[Array, 'R_new']
) – The entries that should be contained in the returned object.- Return type:
- Returns:
The resulting conditional Gaussian diagonal density.
- get_conditional_mu(x, **kwargs)#
Compute the conditional \(\mu\) function \(\mu(X=x) = M x + b\).
- Parameters:
x (
Float[Array, 'N Dx']
) – Instances, the mu should be conditioned on.- Return type:
Array
- Returns:
Conditional means.
- condition_on_x(x, **kwargs)#
Get Gaussian Density conditioned on \(x\).
- Parameters:
x (
Float[Array, 'N Dx']
) – Instances, the mu should be conditioned on.- Return type:
- Returns:
The density conditioned on \(x\).
- set_y(y, **kwargs)#
Set a specific value for \(y\) in \(p(Y=y|X)\) and returns the corresponding conjugate factor.
- Parameters:
y (
Float[Array, 'N Dy']
) – Data for \(y\), where the rth entry is associated with the rth conditional density.- Return type:
- Returns:
The conjugate factor where the first dimension is R.
- affine_joint_transformation(p_x, **kwargs)#
Return the joint density.
\[p(X,Y) = p(Y|X)p(X),\]where \(p(Y|X)\) is the object itself.
- Parameters:
p_x (
GaussianPDF
) – Marginal density over \(X\).- Raises:
RuntimeError – Only works if one of the densities involved have R==1.
- Return type:
- Returns:
The joint density.
- affine_marginal_transformation(p_x, **kwargs)#
Return the marginal density \(p(X)\) given \(p(Y|X)\) and \(p(X)\), where \(p(Y|X)\) is the object itself.
- Parameters:
p_x (
GaussianPDF
) – Marginal density over \(X\).- Raises:
RuntimeError – Only works if one of the densities involved have R==1.
- Return type:
- Returns:
The marginal density.
- affine_conditional_transformation(p_x, **kwargs)#
Return the conditional density \(p(X|Y)\), given \(p(Y|X)\) and \(p(X)\), where \(p(Y|X)\) is the object itself.
- Parameters:
p_x (
GaussianPDF
) – Marginal density over \(X\).- Raises:
RuntimeError – Only works if one of the densities involved have R==1.
- Return type:
- Returns:
ConditionalGaussianPDF
- integrate_log_conditional(p_yx, **kwargs)#
Integrates over the log conditional with respect to the pdf \(p(Y,X)\). I.e.
\[\int \log(p(Y|X))p(Y,X){\rm d}Y{\rm d}X.\]- Parameters:
p_yx (
GaussianPDF
) – Probability density function (first dimensions are \(Y\), last ones are \(X\)).- Raises:
NotImplementedError – Only implemented for R=1.
- Return type:
Float[Array, 'R']
- Returns:
Returns the integral with respect to density \(p(Y,X)\).
- integrate_log_conditional_y(p_x, y=None, **kwargs)#
Computes the expectation over the log conditional, but just over \(X\). I.e. it returns
\[f(Y) = \int \log(p(Y|X))p(X){\rm d}x.\]- Parameters:
p_x (
GaussianPDF
) – Density over \(X\).- Raises:
NotImplementedError – Only implemented for R=1.
- Return type:
Union
[callable
,Float[Array, 'R']
]- Returns:
The integral as function of \(Y\).
- conditional_entropy(p_x, **kwargs)#
Computes the conditional entropy
\[H_{Y|X} = H_{Y,X} - H_X = -\int p(X,Y)\ln p(Y|X) {\rm d}X {\rm d}Y\]- Parameters:
p_x (
GaussianPDF
) – Marginal over conditional variable- Return type:
Float[Array, 'R']
- Returns:
Conditional entropy
- mutual_information(p_x, **kwargs)#
Computes the mutual information
\[I_{Y,X} = H_{Y,X} - H_X - H_Y\]- Parameters:
p_x (
GaussianPDF
) – Marginal over conditional variable.- Return type:
Float[Array, 'R']
- Returns:
Mutual information
- update_Sigma(Sigma_new)#
Updates the covariance matrix \(\Sigma\).
- Parameters:
Sigma_new (
Float[Array, 'R Dy Dy']
) – The new covariance matrix- Raises:
ValueError – Raised when dimension of old and new covariance do not match.
- class NNControlGaussianConditional(*, b=None, Sigma=None, Lambda=None, ln_det_Sigma=None, num_cond_dim, num_control_dim, control_func)#
Bases:
ConditionalGaussianPDF
,Mapping
A conditional Gaussian density, where the transition model is determined through a (known) control variable u.
\[p(Y|X, u) = N(\mu(X|u), \Sigma)\]with the conditional mean function :\(\mu(X|u) = M(u) X + b(u)\),
where \(M(u)\) and \(b(u)\) come from the same neural network.
- Parameters:
Sigma (
Optional
[Float[Array, '1 Dy Dy']
]) – Covariance matrix,num_cond_dim (
int
) – Dimension of the conditional variable.num_control_dim (
int
) – Dimension of the control variablecontrol_func (
callable
) – Mapping control variables to (Dy*(Dx+1)) vector.
- Raises:
NotImplementedError – Raised when the leading dimension of Sigma is not 1.
-
num_cond_dim:
int
#
-
num_control_dim:
int
#
-
control_func:
callable
#
-
M:
Array
#
- property R: int#
Number of conditionals (leading dimension).
- property Dy: int#
Dimensionality of \(Y\).
- property Du: int#
Dimensionality of control parameter $U$.
- property Dx: int#
Dimensionality of \(X\).
- get_M_b(u)#
Construct \(M(u)\) and \(b(u)\) from the output.
- Parameters:
u (
Float[Array, 'R Du']
) – Control variables.- Return type:
Tuple
[Float[Array, 'R Dy Dx']
,Float[Array, 'R Dy']
]- Returns:
Returns \(M(u)\) and \(b(u)\).
- set_control_variable(u)#
Create the conditional for a given control variable u,
\[p(Y|X, u).\]- Parameters:
u (
Float[Array, 'R Du']
) – Control variables.- Return type:
- Returns:
The conditional
- get_conditional_mu(x, u, **kwargs)#
Compute the conditional mean given an \(x\) and an \(u\),
\[\mu(X=x|u) = M(u)x + b(u)\]- Parameters:
x (
Float[Array, 'N Dx']
) – Conditional variable.u (
Float[Array, 'R Du']
) – Control variables.
- Return type:
Float[Array, 'R N Dy']
- Returns:
Conditional mean.
- condition_on_x_u(x, u, **kwargs)#
Return the Gaussian density
\[p(Y|X=x, u)\]- Parameters:
x (
Float[Array, 'N Dx']
) – Conditional variable.u (
Float[Array, 'R Du']
) – Control variables.
- Return type:
- Returns:
Gaussian density conditioned on instances x, and u.
- set_y(y, u, **kwargs)#
Set an instance of Y and U and returns
- Parameters:
y (
Float[Array, 'R Dy']
) – Random variable.u (
Float[Array, 'R Du']
) – Control variables.
- Return type:
- Returns:
The factor with the instantiation.
- affine_joint_transformation(p_x, u, **kwargs)#
Perform the affine joint transformation with a given control variable
\[p(X,Y|u) = p(Y|X,u)p(X),\]where \(p(Y|X,u)\) is the object itself.
- Parameters:
p_x (
GaussianPDF
) – Marginal over \(X\).u (
Float[Array, 'R Du']
) – Control variables.
- Return type:
- Returns:
The joint density.
- affine_marginal_transformation(p_x, u, **kwargs)#
Return the marginal density \(p(Y)\) given \(p(Y|X,u)\) and \(p(X)\), where p(Y|X,u) is the object itself.
- Parameters:
p_x (
GaussianPDF
) – Marginal over \(X\).u (
Float[Array, 'R Du']
) – Control variables.
- Return type:
- Returns:
Marginal density.
- affine_conditional_transformation(p_x, u, **kwargs)#
Return the conditional density \(p(X|Y, u)\), given \(p(Y|X,u)\) and \(p(X)\), where \(p(Y|X,u)\) is the object itself.
- Parameters:
p_x (
GaussianPDF
) – Marginal over \(X\).u (
Float[Array, 'R Du']
) – Control variables.
- Return type:
- Returns:
Conditional density \(p(X|Y, u)\).
- conditional_entropy(p_x, u, **kwargs)#
Compute the conditional entropy
- Parameters:
p_x (
GaussianPDF
) – Marginal over condtional variable.u (
Float[Array, 'R Du']
) – Control variables.
- Return type:
Array
- Returns:
Conditional entropy.
- integrate_log_conditional(phi_yx, u, **kwargs)#
Integrate over the log conditional with respect to the pdf \(p(Y,X)\), i.e.
\[\int \log(p(Y|X,u))p(Y,X){\rm d}Y{\rm d}X.\]- Parameters:
p_yx – Probability density function (first dimensions are \(Y\), last ones are \(X\)).
u (
Float[Array, '1 Du']
) – Control variables.
- Raises:
NotImplementedError – Only one network input allowed.
- Return type:
Array
- Returns:
Returns the integral with respect to density \(p(Y,X)\).
- integrate_log_conditional_y(phi_x, u, y=None, **kwargs)#
Computes the expectation over the log conditional, but just over \(X\). I.e. it returns
\[f(Y) = \int \log(p(Y|X,u))p(X)dX.\]- Parameters:
p_x – Density over \(X\).
u (
Float[Array, '1 Du']
) – Control variables.
- Raises:
NotImplementedError – Only one network input allowed.
- Return type:
Union
[callable
,Float[Array, 'N']
]- Returns:
The integral as function of \(Y\). If provided already evaluated for \(Y=y\).
gaussian_toolbox.factor module#
- class ConjugateFactor(*, Lambda, nu=None, ln_beta=None)#
Bases:
Mapping
Object representing a factor which is conjugate to a Gaussian measure. A general term, which can be multiplied with a Gaussian and the result is still a Gaussian, i.e. has the functional form
\[f(X) = \beta \exp\left(- \frac{1}{2} X^\top\Lambda X + X^\top\nu\right),\]D is the dimension, and R the number of Gaussians. Note: At least \(\Lambda\) or \(\nu\) should be specified!
- Parameters:
Lambda (
Float[Array, 'R D D']
) – Information (precision) matrix of the Gaussian distributions. Must be positive semidefinite.nu (
Optional
[Float[Array, 'R D']
]) – Information vector of a Gaussian distribution. If None all zeros.ln_beta (
Optional
[Float[Array, 'R']
]) – The log constant factor of the factor. If None all zeros.
-
Lambda:
Float[Array, 'R D D']
#
-
nu:
Float[Array, 'R D']
= None#
-
ln_beta:
Float[Array, 'R']
= None#
- property R: int#
Number of factors (leading dimension).
- property D: int#
Dimensionality of \(X\).
- evaluate_ln(x, element_wise=False)#
Evaluate the log-exponential term at \(X=x\).
- Parameters:
x (
Float[Array, 'N D']
) – Points where the factor should be evaluated.element_wise (
bool
) – Evaluates \(x\) for only the corresponding density. Requires the N equals R.
- Raises:
ValueError – Raised if N != R, and elementwise is True.
- Return type:
Union
[Float[Array, 'R N']
,Float[Array, 'R']
]- Returns:
Log exponential term.
- evaluate(x, element_wise=False)#
Evaluate the exponential term at \(X=x\).
- Parameters:
x (
Float[Array, 'N D']
) – Points where the factor should be evaluated.element_wise (
bool
) – Evaluates \(x\) for only the corresponding density. Requires the N equals R.
- Return type:
Union
[Float[Array, 'R N']
,Float[Array, 'R']
]- Returns:
Exponential term.
- slice(indices)#
Return an object with only the specified entries.
- Parameters:
indices (
Int[Array, 'R_new']
) – The entries that should be contained in the returned object.- Return type:
- Returns:
The resulting Conjugate factor.
- product()#
Compute the product over all factors.
\[g(X) = \prod_i f_i(X)\]- Return type:
- Returns:
Product of all factors.
- static get_trace(A)#
Get trace of all matrices in A.
- Parameters:
A (
Float[Array, 'R D D']
) – 3D matrix [_, D, D]- Return type:
Float[Array, 'R']
- Returns:
Returns the trace of all matrices.
- to_dict()#
Write Factor into dict.
- Return type:
Dict
- Returns:
Dictionary with relevant parameters.
- classmethod from_dict(cls_dict)#
Creates class from dictionary
- Parameters:
cls_dict (
dict
) – Dictionary with relevant parameters.- Return type:
- Returns:
The corresponding conjugate factor.
- class LowRankFactor(*, Lambda, nu=None, ln_beta=None)#
Bases:
ConjugateFactor
,Mapping
-
Lambda:
Float[Array, 'R D D']
#
-
nu:
Float[Array, 'R D']
= None#
-
ln_beta:
Float[Array, 'R']
= None#
-
Lambda:
- class OneRankFactor(*, nu=None, ln_beta=None, v, g=None)#
Bases:
ConjugateFactor
,Mapping
A low rank term, which can be multiplied with a Gaussian and the result is still a Gaussian.
It has the functional form
\[f(X) = \beta \exp\left(- \frac{1}{2}X^\top\Lambda X + X^\top\nu\right),\]but \(\Lambda\) is of rank 1 and has the form \(\Lambda=g * vv^\top\).
D is the dimension, and R the number of Gaussians.
- Parameters:
v (
Float[Array, 'R D']
) – Rank one vector for the constructing \(\Lambda\).g (
Optional
[Float[Array, 'R']
]) – Factor for \(\Lambda\). If None, it is assumed to be 1.nu (
Optional
[Float[Array, 'R D']
]) – Information vector of a Gaussian distribution. If None all zeros.ln_beta (
Optional
[Float[Array, 'R']
]) – The log constant factor of the factor. If None all zeros.
-
v:
Float[Array, 'R D']
#
-
g:
Float[Array, 'R']
= None#
-
Lambda:
Float[Array, 'R D D']
#
-
nu:
Float[Array, 'R D']
= None#
-
ln_beta:
Float[Array, 'R']
= None#
- property R: int#
Number of factors (leading dimension).
- property D: int#
Dimensionality of \(X\).
- slice(indices)#
Return an object with only the specified entries.
- Parameters:
indices (
Int[Array, 'R_new']
) – The entries that should be contained in the returned object.- Return type:
- Returns:
The resulting OneRankFactor.
- to_dict()#
Write Factor into dict.
- Return type:
Dict
- Returns:
Dictionary with relevant parameters.
- class LinearFactor(*, nu=None, ln_beta=None)#
Bases:
ConjugateFactor
,Mapping
Object representing a factor which is conjugate to a Gaussian measure.
A general term, which can be multiplied with a Gaussian and the result is still a Gaussian, i.e. has the functional form
\[f(X) = \beta \exp\left(X^\top\nu\right),\]D is the dimension, and R the number of Gaussians.
Note: At least \(\Lambda\) or \(nu\) should be specified!
- Parameters:
Lambda – Is ignored.
nu (
Optional
[Float[Array, 'R D']
]) – Information vector of a Gaussian distribution. If None all zeros.ln_beta (
Optional
[Float[Array, 'R']
]) – The log constant factor of the factor. If None all zeros.
-
ln_beta:
Float[Array, 'R']
= None#
-
Lambda:
Float[Array, 'R D D']
#
- property R: int#
Number of factors (leading dimension).
- property D: int#
Dimensionality of \(X\).
- slice(indices)#
Return an object with only the specified entries.
- Parameters:
indices (
Int[Array, 'R_new']
) – The entries that should be contained in the returned object.- Return type:
- Returns:
The resulting LinearFactor.
- to_dict()#
Write Factor into dict.
- Return type:
Dict
- Returns:
Dictionary with relevant parameters.
- class ConstantFactor(*, ln_beta=None, num_dim)#
Bases:
ConjugateFactor
,Mapping
A term, which can be multiplied with a Gaussian and the result is still a Gaussian.
It has the functional form \(f(X) = \beta\).
D is the dimension, and R the number of Gaussians.
- Parameters:
Lambda – Is ignored.
nu – Is ignored.
ln_beta (
Optional
[Float[Array, 'R']
]) – The log constant factor of the factor.num_dim (
int
) – The dimension of the Gaussian.
-
num_dim:
int
#
-
Lambda:
Float[Array, 'R D D']
#
- property D: int#
Dimensionality of \(X\).
- property R: int#
Number of factors (leading dimension).
- slice(indices)#
Return an object with only the specified entries.
- Parameters:
indices (
Int[Array, 'R_new']
) – The entries that should be contained in the returned object.- Return type:
- Returns:
The resulting ConstantFactor.
- to_dict()#
Write Factor into dict.
- Return type:
Dict
- Returns:
Dictionary with relevant parameters.
gaussian_toolbox.measure module#
- class GaussianMeasure(*, Lambda, nu=None, ln_beta=None, Sigma=None, ln_det_Lambda=None, ln_det_Sigma=None)#
Bases:
ConjugateFactor
,Mapping
A measure with a Gaussian form.
\[u(X) = \beta \exp\left(- \frac{1}{2} X^\top\Lambda X + X^\top\nu\right),\]D is the dimension, and R the number of Gaussians.
- Parameters:
Lambda (
Float[Array, 'R D D']
) – Information (precision) matrix of the Gaussian distributions. Needs to be positive definite.nu (
Optional
[Float[Array, 'R D']
]) – Information vector of a Gaussian distribution. If None all zeros.ln_beta (
Optional
[Float[Array, 'R']
]) – The log constant factor of the factor. If None all zeros.Sigma (
Optional
[Float[Array, 'R D D']
]) – Covariance matrix of the Gaussian distributions. Needs to be positive definite.ln_det_Lambda (
Optional
[Float[Array, 'R']
]) – Log determinant of Lambda.ln_det_Sigma (
Optional
[Float[Array, 'R']
]) – Log determinant of Sigma.
-
Lambda:
Float[Array, 'R D D']
#
-
nu:
Float[Array, 'R D']
= None#
-
ln_beta:
Float[Array, 'R']
= None#
-
Sigma:
Float[Array, 'R D D']
= None#
-
ln_det_Lambda:
Float[Array, 'R']
= None#
-
ln_det_Sigma:
Float[Array, 'R']
= None#
- property integration_dict: Dict#
- slice(indices)#
Return an object with only the specified entries.
- Parameters:
indices (
Int[Array, 'R_new']
) – The entries that should be contained in the returned object.- Return type:
- Returns:
The resulting Gaussian measure.
- compute_lnZ()#
Compute the log partition function.
- invert_lambda()#
Invert precision matrix.
- multiply(factor, update_full=False)#
Compute the product between the measure \(u(X)\) and a conjugate factor \(f(X)\).
Returns \(f(X) * u(X)\).
- Parameters:
factor (
ConjugateFactor
) – The conjugate factor the measure is multiplied with.- Return type:
- Returns:
Resulting GaussianMeasure.
- hadamard(factor, update_full=False)#
Compute the hadamard (componentwise) product between the measure \(u(X)\) and a conjugate factor \(f(X)\).
Returns \(f(X) * u(X)\).
- Parameters:
factor (
ConjugateFactor
) – The conjugate factor the measure is multiplied with.update_full (
bool
) – Whether also the covariance and the log determinants of the new Gaussian measure should be computed.
- Return type:
- Returns:
Resulting GaussianMeasure.
- product()#
Compute the product over all factor.
\[v(X) = \prod_i u_i(X)\]- Return type:
- Returns:
Factor of all factor.
- integrate(expr='1', **kwargs)#
Integrate the indicated expression with respect to the Gaussian measure.
E.g. expr=”(Ax+a)” means that \(\int (AX + a)u(X){\rm d}X\) is computed, and \(A\) and a can be provided.
- Parameters:
expr (
str
) – Indicates the expression that should be integrated. Check measure’s integration dict.- Return type:
']
- Returns:
The integral result.
- log_integral_light()#
Compute the log integral of the exponential term.
\[\log \int u(X) {\rm d}X.\]- Return type:
Float[Array, 'R']
- Returns:
Log integral.
- log_integral()#
Compute the log integral of the exponential term.
\[\log \int u(X) {\rm d}X.\]- Return type:
Float[Array, 'R']
- Returns:
Log integral.
- integral_light()#
Compute the log integral of the exponential term.
\[\int u(X) dX.\]- Return type:
Float[Array, 'R']
- Returns:
Integral.
- integral()#
Compute the log integral of the exponential term.
\[\int u(X) {\rm d}X.\]- Return type:
Float[Array, 'R']
- Returns:
Integral.
- normalize()#
Normalize the term such that
\[\int u(X) {\rm d}X = 1.\]
- is_normalized()#
Check whether measure is normalized
- Return type:
Bool[Array, 'R']
- Returns:
Boolean area indicating which measure is normalized.
- compute_mu()#
Converts from information to mean vector.
- get_density()#
Return the corresponing normalised density object.
- Return type:
- Returns:
Corresponding density object.
- integrate_x()#
Compute the integral.
\[\int X {\rm d}u(X)\]- Return type:
Array
- Returns:
The solved integral.
- integrate_general_linear(A_mat=None, a_vec=None)#
Compute the linear expectation.
\[\int (AX+a) {\rm d}\phi(X),\]with \(\phi(X) = u(X) / \int {\rm d}u(X)\).
- Parameters:
A_mat (
Optional
[Float[Array, '*R K D']
]) – Real valued matrix. If None, it is assumed identity.a_vec (
Optional
[Float[Array, '*R K']
]) – Real valued vector.
- Return type:
Float[Array, 'R K']
- Returns:
The solved integral.
- integrate_xxT()#
Compute the integral
\[\int XX^\top {\rm d}u(X)\]- Return type:
Float[Array, 'R D D']
- Returns:
The solved integral.
- integrate_general_quadratic_inner(A_mat=None, a_vec=None, B_mat=None, b_vec=None)#
Compute the quadratic expectation.
\[\int (AX+a)'(BX+b) {\rm d}\phi(X),\]with \(\phi(X) = u(X) / \int {\rm d}u(X)\).
- Parameters:
A_mat (
Optional
[Float[Array, '*R K D']
]) – Real valued matrix.a_vec (
Optional
[Float[Array, '*R K']
]) – Real valued vector.B_mat (
Optional
[Float[Array, '*R K D']
]) – Real valued matrix.b_vec (
Optional
[Float[Array, '*R K']
]) – Real valued vector.
- Return type:
Float[Array, 'R']
- Returns:
The solved integral.
- integrate_general_quadratic_outer(A_mat=None, a_vec=None, B_mat=None, b_vec=None)#
Compute the quadratic expectation.
\[\int (AX+a)(BX+b)' {\rm d}\phi(X),\]with \(\phi(X) = u(X) / \int {\rm d}u(X)\).
- Parameters:
A_mat (
Optional
[Float[Array, '*R K D']
]) – Real valued matrix.a_vec (
Optional
[Float[Array, '*R K']
]) – Real valued vector.B_mat (
Optional
[Float[Array, '*R L D']
]) – Real valued matrix.b_vec (
Optional
[Float[Array, '*R L']
]) – Real valued vector.
- Return type:
Float[Array, 'R K L']
- Returns:
The solved integral.
- integrate_cubic_outer(A_mat=None, a_vec=None)#
Compute the cubic integration.
\[\int X(A^\top X + a)X^\top {\rm d}u(X).\]- Parameters:
A_mat (
Optional
[Float[Array, '*R 1 D']
]) – Real valued matrix. If None, it is assumed identity.a_vec (
Optional
[Float[Array, '*R 1']
]) – Real valued vector. If None, it is assumed zeros.
- Return type:
Float[Array, 'R D D']
- Returns:
Solved integral.
- integrate_xbxx(b_vec)#
Compute the cubic integral.
\[\int Xb^\top XX^\top {\rm d}u(X)\]- Parameters:
b_vec (
Float[Array, '*R']
) – Real valued vector.- Return type:
Float[Array, 'R D D']
- Returns:
The solved integral.
- integrate_general_cubic_inner(A_mat=None, a_vec=None, B_mat=None, b_vec=None, C_mat=None, c_vec=None)#
Compute the quadratic integration.
\[\int (AX+a)(BX+b)^\top(CX+c) {\rm d}u(X).\]- Parameters:
A_mat (
Optional
[Float[Array, '*R K D']
]) – Real valued matrix.a_vec (
Optional
[Float[Array, '*R K']
]) – Real valued vector.B_mat (
Optional
[Float[Array, '*R L D']
]) – Real valued matrix.b_vec (
Optional
[Float[Array, '*R L']
]) – Real valued vector.C_mat (
Optional
[Float[Array, '*R L D']
]) – Real valued matrix.c_vec (
Optional
[Float[Array, '*R L']
]) – Real valued vector.
- Return type:
Float[Array, 'R K']
- Returns:
The solved integral.
- integrate_general_cubic_outer(A_mat=None, a_vec=None, B_mat=None, b_vec=None, C_mat=None, c_vec=None)#
Compute the quadratic integration
\[\int (AX+a)^\top(Bx+b)(Cx+c)^\top {\rm d}u(X),\]- Parameters:
A_mat (
Optional
[Float[Array, '*R K D']
]) – Real valued matrix.a_vec (
Optional
[Float[Array, '*R K']
]) – Real valued vector.B_mat (
Optional
[Float[Array, '*R K D']
]) – Real valued matrix.b_vec (
Optional
[Float[Array, '*R K']
]) – Real valued vector.C_mat (
Optional
[Float[Array, '*R L D']
]) – Real valued matrix.c_vec (
Optional
[Float[Array, '*R L']
]) – Real valued vector.
- Return type:
Float[Array, 'R L']
- Returns:
The solved integral.
- integrate_general_quartic_outer(A_mat=None, a_vec=None, B_mat=None, b_vec=None, C_mat=None, c_vec=None, D_mat=None, d_vec=None)#
Compute the quartic integral.
\[\int (AX+a)(BX+b)^\top(CX+c)(DX+d)^\top {\rm d}u(X).\]- Parameters:
A_mat (
Optional
[Float[Array, '*R K D']
]) – Real valued matrix.a_vec (
Optional
[Float[Array, '*R K']
]) – Real valued vector.B_mat (
Optional
[Float[Array, '*R L D']
]) – Real valued matrix.b_vec (
Optional
[Float[Array, '*R L']
]) – Real valued vector.C_mat (
Optional
[Float[Array, '*R L D']
]) – Real valued matrix.c_vec (
Optional
[Float[Array, '*R L']
]) – Real valued vector.D_mat (
Optional
[Float[Array, '*R M D']
]) – Real valued matrix.d_vec (
Optional
[Float[Array, '*R M']
]) – Real valued vector.
- Return type:
Float[Array, 'R K M']
- Returns:
The solved integral.
- integrate_general_quartic_inner(A_mat=None, a_vec=None, B_mat=None, b_vec=None, C_mat=None, c_vec=None, D_mat=None, d_vec=None)#
Compute the quartic integral.
\[\int (AX+a)(BX+b)'(CX+c)(DX+d)' {\rm d}u(X).\]- Parameters:
A_mat (
Optional
[Float[Array, '*R K D']
]) – Real valued matrix.a_vec (
Optional
[Float[Array, '*R K']
]) – Real valued vector.B_mat (
Optional
[Float[Array, '*R K D']
]) – Real valued matrix.b_vec (
Optional
[Float[Array, '*R K']
]) – Real valued vector.C_mat (
Optional
[Float[Array, '*R L D']
]) – Real valued matrix.c_vec (
Optional
[Float[Array, '*R L']
]) – Real valued vector.D_mat (
Optional
[Float[Array, '*R L D']
]) – Real valued matrix.d_vec (
Optional
[Float[Array, '*R L']
]) – Real valued vector.
- Return type:
Float[Array, 'R']
- Returns:
The solved integral.
- integrate_log_factor(factor)#
Integrates over a log factor.
- Parameters:
factor (
ConjugateFactor
) – The factor, which will be integrated.- Return type:
Float[Array, 'R']
- Returns:
The integral
- class GaussianDiagMeasure(*, Lambda, nu=None, ln_beta=None, Sigma=None, ln_det_Lambda=None, ln_det_Sigma=None)#
Bases:
GaussianMeasure
,Mapping
A measure with a Gaussian form.
\[u(X) = \beta \exp\left(- \frac{1}{2} X^\top\Lambda X + X^\top\nu\right),\]D is the dimension, and R the number of Gaussians.
- Parameters:
Lambda (
Float[Array, 'R D D']
) – Information (precision) matrix of the Gaussian distributions. Needs to be positive definite and diagonal.nu (
Optional
[Float[Array, 'R D']
]) – Information vector of a Gaussian distribution. If None all zeros.ln_beta (
Optional
[Float[Array, 'R']
]) – The log constant factor of the factor. If None all zeros.Sigma (
Optional
[Float[Array, 'R D D']
]) – Covariance matrix of the Gaussian distributions. Needs to be positive definite.ln_det_Lambda (
Optional
[Float[Array, 'R']
]) – Log determinant of Lambda.ln_det_Sigma (
Optional
[Float[Array, 'R']
]) – Log determinant of Sigma.
- invert_lambda()#
Invert precision matrix.
- slice(indices)#
Return an object with only the specified entries.
- Parameters:
indices (
Int[Array, 'R_new']
) – The entries that should be contained in the returned object.- Return type:
- Returns:
The resulting Gaussian diagonal measure.
- product()#
Computes the product over all factor.
\[v(X) = \prod_i u_i(X)\]- Return type:
- Returns:
Factor of all factor.
gaussian_toolbox.pdf module#
- class GaussianPDF(*, Lambda=None, Sigma=None, ln_det_Lambda=None, ln_det_Sigma=None, mu)#
Bases:
GaussianMeasure
,Mapping
A normalized Gaussian density, with specified mean and covariance matrix.
- Parameters:
Sigma (
Optional
[Float[Array, 'R D D']
]) – Covariance matrices of the Gaussian densities.mu (
Float[Array, 'R D']
) – Mean of the Gaussians.Lambda (
Optional
[Float[Array, 'R D D']
]) – Information (precision) matrix of the Gaussians.ln_det_Sigma (
Optional
[Float[Array, 'R']
]) – Log determinant of the covariance matrix.
-
mu:
Float[Array, 'R D']
#
-
Lambda:
Float[Array, 'R D D']
= None#
-
ln_det_Sigma:
Float[Array, 'R']
= None#
-
lnZ:
Float[Array, 'R']
= None#
- sample(key, num_samples)#
Sample from the Gaussian density.
- Parameters:
key (
PRNGKey
) – Jax pseudo random number generator.num_samples (
int
) – Number og samples.
- Return type:
Float[Array, 'N R D']
- Returns:
Samples.
- slice(indices)#
Return an object with only the specified entries.
- Parameters:
indices (
Int[Array, 'R_new']
) – The entries that should be contained in the returned object.- Return type:
- Returns:
The resulting Gaussian density.
- update(indices, density)#
Update densities at indicated entries.
- Parameters:
indices (
Int[Array, 'R_update']
) – The entries that should be updated.density (
GaussianPDF
) – New densities.
- get_marginal(dim_x)#
Get the marginal of the indicated dimensions.
- Parameters:
dim_x (
Int[Array, 'Dx']
) – The dimensions of the variables, the marginal is required for.- Return type:
- Returns:
The resulting marginal Gaussian density.
- entropy()#
Computes the entropy of the density.
\[H_X = -\int p(X)\log p(X) {\rm d}X\]- Return type:
Float[Array, 'R']
- Returns:
Entropy of the density
- kl_divergence(p1)#
Compute the Kulback Leibler divergence between two multivariate Gaussians. :rtype:
Float[Array, 'R']
D_KL(p|p1) = int p(X)log frac{p(X)}{p_1(X)} {rm d}X
- condition_on(dim_y)#
Return density conditioned on indicated dimensions, i.e. \(p(X|Y)\).
- Parameters:
dim_y (
Float[Array, 'Dy']
) – The dimensions of the variables, that should be conditioned on.- Return type:
- Returns:
The corresponding conditional Gaussian density \(p(X|Y)\).
- condition_on_explicit(dim_y, dim_x)#
Returns density conditioned on indicated dimensions, i.e. \(p(X|Y)\).
- Parameters:
dim_y (
Float[Array, 'R Dy']
) – The dimensions of the variables, that should be conditioned on.dim_x (
Float[Array, 'R Dx']
) – The dimensions of the variables, that should be still be free.
- Return type:
- Returns:
The corresponding conditional Gaussian density \(p(X|Y)\).
- get_density_of_linear_sum(W, b=None)#
Returns density of linear sum of Gaussians.
- Parameters:
W (
Float[Array, 'R Dsum D']
) – Weight matrix.b (
Optional
[Float[Array, 'R Dsum']
]) – Bias vector.
- Return type:
- Returns:
Gaussian density of linear sum.
- to_dict()#
Write Gaussian into dict.
- Return type:
Dict
- Returns:
Dictionary with relevant parameters.
- class GaussianDiagPDF(*, Lambda=None, Sigma=None, ln_det_Lambda=None, ln_det_Sigma=None, mu)#
Bases:
GaussianPDF
,GaussianDiagMeasure
,Mapping
A normalized Gaussian density, with specified mean and covariance matrix.
\(\Sigma\) should be diagonal (and hence \(\Lambda\)).
- Parameters:
Sigma (
Optional
[Float[Array, 'R D D']
]) – Covariance matrices of the Gaussian densities. Must be diagonal.mu (
Float[Array, 'R D']
) – Mean of the Gaussians.Lambda (
Optional
[Float[Array, 'R D D']
]) – Information (precision) matrix of the Gaussians.ln_det_Sigma (
Optional
[Float[Array, 'R']
]) – Log determinant of the covariance matrix.
-
mu:
Float[Array, 'R D']
#
-
Lambda:
Float[Array, 'R D D']
= None#
-
ln_det_Sigma:
Float[Array, 'R']
= None#
-
lnZ:
Float[Array, 'R']
= None#
- slice(indices)#
Return an object with only the specified entries.
- Parameters:
indices (
Int[Array, 'R_new']
) – The entries that should be contained in the returned object.- Return type:
- Returns:
The resulting Gaussian diagonal density.
- update(indices, density)#
Update densities at indicated entries.
- Parameters:
indices (
Int[Array, 'R_update']
) – The entries that should be updated.density (
GaussianDiagPDF
) – New densities.
- get_marginal(dim_idx)#
Get the marginal of the indicated dimensions.
- Parameters:
dim_idx (
Int[Array, 'Dx']
) – The dimensions of the variables, the marginal is required for.- Return type:
- Returns:
The resulting marginal Gaussian density.