Stan  2.10.0
probability, sampling & optimization
Public Member Functions | List of all members
stan::variational::normal_fullrank Class Reference

Variational family approximation with full-rank multivariate normal distribution. More...

#include <normal_fullrank.hpp>

Inheritance diagram for stan::variational::normal_fullrank:
stan::variational::base_family

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_fullrankoperator= (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_fullrankoperator+= (const normal_fullrank &rhs)
 Add the mean and Cholesky factor of the covariance matrix of the specified approximation to this approximation. More...
 
normal_fullrankoperator/= (const normal_fullrank &rhs)
 Return this approximation after elementwise division by the specified approximation's mean and Cholesky factor for covariance. More...
 
normal_fullrankoperator+= (double scalar)
 Return this approximation after adding the specified scalar to each entry in the mean and cholesky factor for covariance. More...
 
normal_fullrankoperator*= (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...
 
- Public Member Functions inherited from stan::variational::base_family
 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

- Protected Member Functions inherited from stan::variational::base_family
void write_error_msg_ (std::ostream *error_msgs, const std::exception &e) const
 

Detailed Description

Variational family approximation with full-rank multivariate normal distribution.

Definition at line 35 of file normal_fullrank.hpp.

Constructor & Destructor Documentation

stan::variational::normal_fullrank::normal_fullrank ( size_t  dimension)
inlineexplicit

Construct a variational distribution of the specified dimensionality with a zero mean and Cholesky factor of a zero covariance matrix.

Parameters
[in]dimensionDimensionality of distribution.

Definition at line 103 of file normal_fullrank.hpp.

stan::variational::normal_fullrank::normal_fullrank ( const Eigen::VectorXd &  cont_params)
inlineexplicit

Construct a variational distribution with specified mean vector and Cholesky factor for identity covariance.

Parameters
[in]cont_paramsMean vector.

Definition at line 116 of file normal_fullrank.hpp.

stan::variational::normal_fullrank::normal_fullrank ( const Eigen::VectorXd &  mu,
const Eigen::MatrixXd &  L_chol 
)
inline

Construct a variational distribution with specified mean and Cholesky factor for covariance.

Warning: Positive-definiteness is not enforced for the Cholesky factor.

Parameters
[in]muMean vector.
[in]L_cholCholesky factor of covariance.
Exceptions
std::domain_errorIf 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.

Member Function Documentation

template<class M , class BaseRNG >
void stan::variational::normal_fullrank::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
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

Template Parameters
MModel class.
BaseRNGClass of base random number generator.
Parameters
[in]elbo_gradApproximation to store "blackbox" gradient.
[in]mModel.
[in]cont_paramsContinuous parameters.
[in]n_monte_carlo_gradSample size for gradient computation.
[in,out]rngRandom number generator.
[in,out]message_writerwriter for messages
Exceptions
std::domain_errorIf the number of divergent iterations exceeds its specified bounds.

Definition at line 414 of file normal_fullrank.hpp.

int stan::variational::normal_fullrank::dimension ( ) const
inline

Return the dimensionality of the approximation.

Definition at line 148 of file normal_fullrank.hpp.

double stan::variational::normal_fullrank::entropy ( ) const
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)))).

Returns
Entropy of this approximation

Definition at line 347 of file normal_fullrank.hpp.

const Eigen::MatrixXd& stan::variational::normal_fullrank::L_chol ( ) const
inline

Return the Cholesky factor of the covariance matrix.

Definition at line 158 of file normal_fullrank.hpp.

const Eigen::VectorXd& stan::variational::normal_fullrank::mean ( ) const
inline

Returns the mean vector for this approximation.

See: mu().

Returns
Mean vector for this approximation.

Definition at line 334 of file normal_fullrank.hpp.

const Eigen::VectorXd& stan::variational::normal_fullrank::mu ( ) const
inline

Return the mean vector.

Definition at line 153 of file normal_fullrank.hpp.

normal_fullrank& stan::variational::normal_fullrank::operator*= ( double  scalar)
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.

Parameters
[in]scalarScalar to add.
Returns
This approximation after elementwise addition of the specified scalar.

Definition at line 321 of file normal_fullrank.hpp.

normal_fullrank& stan::variational::normal_fullrank::operator+= ( const normal_fullrank rhs)
inline

Add the mean and Cholesky factor of the covariance matrix of the specified approximation to this approximation.

Parameters
[in]rhsApproximation from which to gather the mean and covariance.
Returns
This approximation after adding the specified approximation.
Exceptions
std::domain_errorIf the dimensionality of the specified approximation does not match this approximation's dimensionality.

Definition at line 256 of file normal_fullrank.hpp.

normal_fullrank& stan::variational::normal_fullrank::operator+= ( double  scalar)
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.

Parameters
[in]scalarScalar to add.
Returns
This approximation after elementwise addition of the specified scalar.

Definition at line 303 of file normal_fullrank.hpp.

normal_fullrank& stan::variational::normal_fullrank::operator/= ( const normal_fullrank rhs)
inline

Return this approximation after elementwise division by the specified approximation's mean and Cholesky factor for covariance.

Parameters
[in]rhsApproximation from which to gather the mean and covariance.
Returns
This approximation after elementwise division by the specified approximation.
Exceptions
std::domain_errorIf the dimensionality of the specified approximation does not match this approximation's dimensionality.

Definition at line 279 of file normal_fullrank.hpp.

normal_fullrank& stan::variational::normal_fullrank::operator= ( const normal_fullrank rhs)
inline

Return this approximation after setting its mean vector and Cholesky factor for covariance to the values given by the specified approximation.

Parameters
[in]rhsApproximation from which to gather the mean and covariance.
Returns
This approximation after assignment.
Exceptions
std::domain_errorIf the dimensionality of the specified approximation does not match this approximation's dimensionality.

Definition at line 234 of file normal_fullrank.hpp.

template<class BaseRNG >
void stan::variational::normal_fullrank::sample ( BaseRNG &  rng,
Eigen::VectorXd &  eta 
) const
inline

Set the specified vector to a draw from this variational approximation using the specified random number generator.

Template Parameters
BaseRNGClass of random number generator.
Parameters
[in,out]rngBase random number generator.
[out]etaRandom draw.
Returns
A sample from the variational distribution.

Definition at line 390 of file normal_fullrank.hpp.

void stan::variational::normal_fullrank::set_L_chol ( const Eigen::MatrixXd &  L_chol)
inline

Set the Cholesky factor to the specified value.

Parameters
L_cholCholesky factor of covariance matrix.
Exceptions
std::domain_errorIf 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.

void stan::variational::normal_fullrank::set_mu ( const Eigen::VectorXd &  mu)
inline

Set the mean vector to the specified value.

Parameters
[in]muMean vector.
Exceptions
std::domain_errorIf 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.

void stan::variational::normal_fullrank::set_to_zero ( )
inline

Set the mean vector and Cholesky factor for the covariance matrix to zero.

Definition at line 192 of file normal_fullrank.hpp.

normal_fullrank stan::variational::normal_fullrank::sqrt ( ) const
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.

normal_fullrank stan::variational::normal_fullrank::square ( ) const
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.

Eigen::VectorXd stan::variational::normal_fullrank::transform ( const Eigen::VectorXd &  eta) const
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.

Parameters
[in]etaVector to transform.
Exceptions
std::domain_errorIf the specified vector's size does not match the dimensionality of this approximation.
Returns
Transformed vector.

Definition at line 369 of file normal_fullrank.hpp.


The documentation for this class was generated from the following file:

     [ Stan Home Page ] © 2011–2016, Stan Development Team.