projnormal.formulas.projected_normal_Bc.sampling

Sampling functions for the general projected normal distribution.

Functions

empirical_moments(mean_x, covariance_x, ...)

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

sample(mean_x, covariance_x, n_samples, const)

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

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

Compute the mean, covariance and second moment of the variable \(y = x/\sqrt{x^T B x + c}\) where \(x \sim \mathcal{N}(\mu_x, \Sigma_x)\), \(B\) is a symmetric positive definite matrix, and \(c\) is a positive constant added to the denominator, 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.

  • const (torch.Tensor) – Constant added to the denominator. Shape is ().

  • 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

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

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

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.

  • const (torch.Tensor) – Constant added to the denominator. Shape is ().

  • 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