projnormal.formulas.projected_normal_B

Formulas for the distribution of \(y=x/\sqrt{x^T B x}\).

empirical_moments(mean_x, covariance_x, n_samples, B=None, B_chol=None)

Compute the mean, covariance and second moment of the variable \(y = x/\sqrt{x^T B x}\) where \(x \sim \mathcal{N}(\mu_x, \Sigma_x)\) and \(B\) is a symmetric positive definite matrix, by sampling from the distribution.

Parameters:
  • mean_x (torch.Tensor) – Mean of x. Shape is (n_dim,).

  • covariance_x (torch.Tensor) – Covariance of x. Shape is (n_dim, n_dim).

  • n_samples (int) – Number of samples to draw.

  • B (torch.Tensor, optional) – Matrix B used in the denominator of the projection. If not provided, the identity matrix is used. Shape is (n_dim, n_dim).

  • B_chol (torch.Tensor, optional) – Cholesky decomposition matrix L, such that B = LL’. Can be provided to avoid recomputing it. Shape is (n_dim, n_dim).

Returns:

Dictionary with the keys mean, covariance, and second_moment, containing the empirical moments of the projected normal distribution.

Return type:

dict

log_pdf(mean_x, covariance_x, y, B=None)

Compute the log-pdf at points y for the distribution of the variable \(y = x/\sqrt{x^T B x}\), where \(x \sim \mathcal{N}(\mu_x, \Sigma_x)\) and \(B\) is a symmetric positive definite matrix.

Parameters:
  • mean_x (torch.Tensor) – Mean of x. Shape is (n_dim,).

  • covariance_x (torch.Tensor) – Covariance of x. Shape is (n_dim, n_dim).

  • y (torch.Tensor) – Points where to evaluate the PDF. Shape is (n_points, n_dim).

  • B (torch.Tensor, optional) – Matrix B used in the denominator of the projection. If not provided, the identity matrix is used. Shape is (n_dim, n_dim).

Returns:

Log-PDF evaluated at each y. Shape is (n_points,).

Return type:

torch.Tensor

mean(mean_x, covariance_x, B=None, B_chol=None)

Compute the mean of \(y = x/\sqrt{x^T B x}\), where \(x \sim \mathcal{N}(\mu_x, \Sigma_x)\) and \(B\) is a symmetric positive definite matrix. Uses a Taylor approximation. (\(y\) is distributed on the ellipse defined by \(B\).).

Parameters:
  • mean_x (torch.Tensor) – Mean of x. Shape is (n_dim,).

  • covariance_x (torch.Tensor) – Covariance of x. Shape is (n_dim, n_dim).

  • B (torch.Tensor, optional) – Symmetric positive definite matrix defining the ellipse. Shape is (n_dim, n_dim).

  • B_chol (torch.Tensor, optional) – Cholesky decomposition of B. Can be provided to avoid recomputing it. Shape is (n_dim, n_dim).

Returns:

Expected value for the projected normal on ellipse. Shape is (n_dim,).

Return type:

torch.Tensor

pdf(mean_x, covariance_x, y, B=None)

Compute the pdf at points y for the distribution of the variable \(y = x/\sqrt{x^T B x}\), where \(x \sim \mathcal{N}(\mu_x, \Sigma_x)\) and \(B\) is a symmetric positive definite matrix.

Parameters:
  • mean_x (torch.Tensor) – Mean of x. Shape is (n_dim,).

  • covariance_x (torch.Tensor) – Covariance of x. Shape is (n_dim, n_dim).

  • y (torch.Tensor) – Points where to evaluate the PDF. Shape is (n_points, n_dim).

  • B (torch.Tensor, optional) – Matrix B used in the denominator of the projection. If not provided, the identity matrix is used. Shape is (n_dim, n_dim).

Returns:

PDF evaluated at each y. Shape is (n_points,).

Return type:

torch.Tensor

sample(mean_x, covariance_x, n_samples, B=None, B_chol=None)

Sample the variable \(y = x/\sqrt{x^T B x}\) where \(x \sim \mathcal{N}(\mu_x, \Sigma_x)\) and \(B\) is a symmetric positive definite matrix.

Parameters:
  • mean_x (torch.Tensor) – Mean of x. Shape is (n_dim,).

  • covariance_x (torch.Tensor) – Covariance of x. Shape is (n_dim, n_dim).

  • n_samples (int) – Number of samples to draw.

  • B (torch.Tensor, optional) – Matrix B used in the denominator of the projection. If not provided, the identity matrix is used. Shape is (n_dim, n_dim).

  • B_chol (torch.Tensor, optional) – Cholesky decomposition matrix L, such that B = LL’. Can be provided to avoid recomputing it. Shape is (n_dim, n_dim).

Returns:

Samples from the projected normal. Shape is (n_samples, n_dim).

Return type:

torch.Tensor

second_moment(mean_x, covariance_x, B=None, B_chol=None)

Compute the Taylor approximation to the second moment matrix of the variable Y = X/(X’BX)^0.5, where X~N(mean_x, covariance_x). Y has a general projected normal distribution.

Parameters:
  • mean_x (torch.Tensor) – Mean of x. Shape is (n_dim,).

  • covariance_x (torch.Tensor) – Covariance of x. Shape is (n_dim, n_dim).

  • B (torch.Tensor, optional) – Symmetric positive definite matrix defining the ellipse. Shape is (n_dim, n_dim).

  • B_chol (torch.Tensor, optional) – Cholesky decomposition of B. Can be provided to avoid recomputing it. Shape is (n_dim, n_dim).

Returns:

Second moment matrix of \(y\). Shape is (n_dim, n_dim).

Return type:

torch.Tensor

Modules

moments

Approximation to the moments of the general projected normal distribution projected onto ellipse given by matrix B.

probability

Probability density function (PDF) for the general projected normal distribution.

sampling

Sampling functions for the general projected normal distribution.