![]() |
Stan
2.10.0
probability, sampling & optimization
|
Variational family approximation with full-rank multivariate normal distribution. More...
#include <normal_fullrank.hpp>
Public Member Functions | |
normal_fullrank (size_t dimension) | |
Construct a variational distribution of the specified dimensionality with a zero mean and Cholesky factor of a zero covariance matrix. More... | |
normal_fullrank (const Eigen::VectorXd &cont_params) | |
Construct a variational distribution with specified mean vector and Cholesky factor for identity covariance. More... | |
normal_fullrank (const Eigen::VectorXd &mu, const Eigen::MatrixXd &L_chol) | |
Construct a variational distribution with specified mean and Cholesky factor for covariance. More... | |
int | dimension () const |
Return the dimensionality of the approximation. More... | |
const Eigen::VectorXd & | mu () const |
Return the mean vector. More... | |
const Eigen::MatrixXd & | L_chol () const |
Return the Cholesky factor of the covariance matrix. More... | |
void | set_mu (const Eigen::VectorXd &mu) |
Set the mean vector to the specified value. More... | |
void | set_L_chol (const Eigen::MatrixXd &L_chol) |
Set the Cholesky factor to the specified value. More... | |
void | set_to_zero () |
Set the mean vector and Cholesky factor for the covariance matrix to zero. More... | |
normal_fullrank | square () const |
Return a new full rank approximation resulting from squaring the entries in the mean and Cholesky factor for the covariance matrix. More... | |
normal_fullrank | sqrt () const |
Return a new full rank approximation resulting from taking the square root of the entries in the mean and Cholesky factor for the covariance matrix. More... | |
normal_fullrank & | operator= (const normal_fullrank &rhs) |
Return this approximation after setting its mean vector and Cholesky factor for covariance to the values given by the specified approximation. More... | |
normal_fullrank & | operator+= (const normal_fullrank &rhs) |
Add the mean and Cholesky factor of the covariance matrix of the specified approximation to this approximation. More... | |
normal_fullrank & | operator/= (const normal_fullrank &rhs) |
Return this approximation after elementwise division by the specified approximation's mean and Cholesky factor for covariance. More... | |
normal_fullrank & | operator+= (double scalar) |
Return this approximation after adding the specified scalar to each entry in the mean and cholesky factor for covariance. More... | |
normal_fullrank & | operator*= (double scalar) |
Return this approximation after multiplying by the specified scalar to each entry in the mean and cholesky factor for covariance. More... | |
const Eigen::VectorXd & | mean () const |
Returns the mean vector for this approximation. More... | |
double | entropy () const |
Return the entropy of this approximation. More... | |
Eigen::VectorXd | transform (const Eigen::VectorXd &eta) const |
Return the transform of the sepcified vector using the Cholesky factor and mean vector. More... | |
template<class BaseRNG > | |
void | sample (BaseRNG &rng, Eigen::VectorXd &eta) const |
Set the specified vector to a draw from this variational approximation using the specified random number generator. More... | |
template<class M , class BaseRNG > | |
void | calc_grad (normal_fullrank &elbo_grad, M &m, Eigen::VectorXd &cont_params, int n_monte_carlo_grad, BaseRNG &rng, interface_callbacks::writer::base_writer &message_writer) const |
Calculates the "blackbox" gradient with respect to BOTH the location vector (mu) and the cholesky factor of the scale matrix (L_chol) in parallel. More... | |
![]() | |
base_family () | |
base_family | square () const |
base_family | sqrt () const |
base_family | operator= (const base_family &rhs) |
base_family | operator+= (const base_family &rhs) |
base_family | operator/= (const base_family &rhs) |
base_family | operator+= (double scalar) |
base_family | operator*= (double scalar) |
const Eigen::VectorXd & | mean () const |
double | entropy () const |
Eigen::VectorXd | transform (const Eigen::VectorXd &eta) const |
template<class BaseRNG > | |
void | sample (BaseRNG &rng, Eigen::VectorXd &eta) const |
template<class M , class BaseRNG > | |
void | calc_grad (base_family &elbo_grad, M &m, Eigen::VectorXd &cont_params, int n_monte_carlo_grad, BaseRNG &rng, interface_callbacks::writer::base_writer &message_writer) const |
Additional Inherited Members | |
![]() | |
void | write_error_msg_ (std::ostream *error_msgs, const std::exception &e) const |
Variational family approximation with full-rank multivariate normal distribution.
Definition at line 35 of file normal_fullrank.hpp.
|
inlineexplicit |
Construct a variational distribution of the specified dimensionality with a zero mean and Cholesky factor of a zero covariance matrix.
[in] | dimension | Dimensionality of distribution. |
Definition at line 103 of file normal_fullrank.hpp.
|
inlineexplicit |
Construct a variational distribution with specified mean vector and Cholesky factor for identity covariance.
[in] | cont_params | Mean vector. |
Definition at line 116 of file normal_fullrank.hpp.
|
inline |
Construct a variational distribution with specified mean and Cholesky factor for covariance.
Warning: Positive-definiteness is not enforced for the Cholesky factor.
[in] | mu | Mean vector. |
[in] | L_chol | Cholesky factor of covariance. |
std::domain_error | If the Cholesky factor is not square or not lower triangular, if the mean and Cholesky factor have different dimensionality, or if any of the elements is not-a-number. |
Definition at line 137 of file normal_fullrank.hpp.
|
inline |
Calculates the "blackbox" gradient with respect to BOTH the location vector (mu) and the cholesky factor of the scale matrix (L_chol) in parallel.
It uses the same gradient computed from a set of Monte Carlo samples
M | Model class. |
BaseRNG | Class of base random number generator. |
[in] | elbo_grad | Approximation to store "blackbox" gradient. |
[in] | m | Model. |
[in] | cont_params | Continuous parameters. |
[in] | n_monte_carlo_grad | Sample size for gradient computation. |
[in,out] | rng | Random number generator. |
[in,out] | message_writer | writer for messages |
std::domain_error | If the number of divergent iterations exceeds its specified bounds. |
Definition at line 414 of file normal_fullrank.hpp.
|
inline |
Return the dimensionality of the approximation.
Definition at line 148 of file normal_fullrank.hpp.
|
inline |
Return the entropy of this approximation.
The entropy is defined by 0.5 * dim * (1+log2pi) + 0.5 * log det (L^T L) = 0.5 * dim * (1+log2pi) + sum(log(abs(diag(L)))).
Definition at line 347 of file normal_fullrank.hpp.
|
inline |
Return the Cholesky factor of the covariance matrix.
Definition at line 158 of file normal_fullrank.hpp.
|
inline |
Returns the mean vector for this approximation.
See: mu()
.
Definition at line 334 of file normal_fullrank.hpp.
|
inline |
Return the mean vector.
Definition at line 153 of file normal_fullrank.hpp.
|
inline |
Return this approximation after multiplying by the specified scalar to each entry in the mean and cholesky factor for covariance.
Warning: No finiteness check is made on the scalar, so it may introduce NaNs.
[in] | scalar | Scalar to add. |
Definition at line 321 of file normal_fullrank.hpp.
|
inline |
Add the mean and Cholesky factor of the covariance matrix of the specified approximation to this approximation.
[in] | rhs | Approximation from which to gather the mean and covariance. |
std::domain_error | If the dimensionality of the specified approximation does not match this approximation's dimensionality. |
Definition at line 256 of file normal_fullrank.hpp.
|
inline |
Return this approximation after adding the specified scalar to each entry in the mean and cholesky factor for covariance.
Warning: No finiteness check is made on the scalar, so it may introduce NaNs.
[in] | scalar | Scalar to add. |
Definition at line 303 of file normal_fullrank.hpp.
|
inline |
Return this approximation after elementwise division by the specified approximation's mean and Cholesky factor for covariance.
[in] | rhs | Approximation from which to gather the mean and covariance. |
std::domain_error | If the dimensionality of the specified approximation does not match this approximation's dimensionality. |
Definition at line 279 of file normal_fullrank.hpp.
|
inline |
Return this approximation after setting its mean vector and Cholesky factor for covariance to the values given by the specified approximation.
[in] | rhs | Approximation from which to gather the mean and covariance. |
std::domain_error | If the dimensionality of the specified approximation does not match this approximation's dimensionality. |
Definition at line 234 of file normal_fullrank.hpp.
|
inline |
Set the specified vector to a draw from this variational approximation using the specified random number generator.
BaseRNG | Class of random number generator. |
[in,out] | rng | Base random number generator. |
[out] | eta | Random draw. |
Definition at line 390 of file normal_fullrank.hpp.
|
inline |
Set the Cholesky factor to the specified value.
L_chol | Cholesky factor of covariance matrix. |
std::domain_error | If the specified matrix is not square, is not lower triangular, if its size does not match the dimensionality of this approximation, or if it contains not-a-number values. |
Definition at line 182 of file normal_fullrank.hpp.
|
inline |
Set the mean vector to the specified value.
[in] | mu | Mean vector. |
std::domain_error | If the size of the specified mean vector does not match the stored dimension of this approximation. |
Definition at line 167 of file normal_fullrank.hpp.
|
inline |
Set the mean vector and Cholesky factor for the covariance matrix to zero.
Definition at line 192 of file normal_fullrank.hpp.
|
inline |
Return a new full rank approximation resulting from taking the square root of the entries in the mean and Cholesky factor for the covariance matrix.
The new approximation does not hold any references to this approximation.
Warning: No checks are carried out to ensure the entries are non-negative before taking square roots, so not-a-number values may result.
Definition at line 218 of file normal_fullrank.hpp.
|
inline |
Return a new full rank approximation resulting from squaring the entries in the mean and Cholesky factor for the covariance matrix.
The new approximation does not hold any references to this approximation.
Definition at line 203 of file normal_fullrank.hpp.
|
inline |
Return the transform of the sepcified vector using the Cholesky factor and mean vector.
The transform is defined by S^{-1}(eta) = L_chol * eta + mu.
[in] | eta | Vector to transform. |
std::domain_error | If the specified vector's size does not match the dimensionality of this approximation. |
Definition at line 369 of file normal_fullrank.hpp.