projnormal.classes.ellipse
Class for the general projected normal distribution.
Classes
|
Projected normal distribution variant, describing the variable \(y=x/\sqrt{x^T B x}\), where \(x \sim \mathcal{N}(\mu_x, \Sigma_x)\) follows a multivariate normal distribution and \(B\) is a symmetric positive definite matrix. |
- class ProjNormalEllipse(n_dim=None, mean_x=None, covariance_x=None, B=None)
Bases:
ProjNormalProjected normal distribution variant, describing the variable \(y=x/\sqrt{x^T B x}\), where \(x \sim \mathcal{N}(\mu_x, \Sigma_x)\) follows a multivariate normal distribution and \(B\) is a symmetric positive definite matrix.
- Parameters:
n_dim (
int) – Dimension of \(x\) (the embedding space). Optional: Ifmean_xandcovariance_xare provided, it is not required.mean_x (
torch.Tensor, optional) – Mean of \(x\). Shape(n_dim). Default is random.covariance_x (
torch.Tensor, optional) – Covariance of \(x\). Shape(n_dim, n_dim). Default is the identity.B (
torch.Tensor, optional) – SPD matrix defining the ellipse. Shape(n_dim, n_dim). Default is the identity matrix.
- Variables:
mean_x (
torch.Tensor) – Mean of \(x\). Learnable parameter constrained to have unit norm. Shape(n_dim).covariance_x (
torch.Tensor) – Covariance of \(x\). Learnable parameter constrained to be SPD. Shape(n_dim, n_dim).B (
torch.Tensor) – Quadratic form matrix of the denominator. Shape(n_dim, n_dim). Learnable parameter constrained to be SPD.
- log_pdf(y)
Compute the log pdf of points y.
- Parameters:
y (
torch.Tensor) – Points to evaluate the log pdf. Shape(n_points, n_dim).- Returns:
Log-PDF of y. Shape
(n_points).- Return type:
torch.Tensor
- moments()
Compute moments of the distribution via Taylor approximation.
- Returns:
Dictionary with keys
mean,covarianceandsecond_moment, containing the corresponding moments of the distribution.- Return type:
dict
- moments_empirical(n_samples=500000)
Compute moments of the distribution via sampling.
- Parameters:
n_samples (
int) – Number of samples to draw for empirical moments. Default is200000.- Returns:
Dictionary with keys
mean,covarianceandsecond_moment, containing the corresponding moments of the distribution.- Return type:
dict
- pdf(y)
Compute the pdf of points y.
- Parameters:
y (
torch.Tensor) – Points to evaluate the pdf. Shape(n_points, n_dim).- Returns:
PDF of the points y. Shape
(n_points).- Return type:
torch.Tensor
- sample(n_samples)
Sample from the distribution.
- Parameters:
n_samples (
int) – Number of samples to draw.- Returns:
Samples from the distribution. Shape
(n_samples, n_dim).- Return type:
torch.Tensor