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

Variational family approximation with mean-field (diagonal covariance) multivariate normal distribution. More...

#include <normal_meanfield.hpp>

Inheritance diagram for stan::variational::normal_meanfield:
stan::variational::base_family

Public Member Functions

 normal_meanfield (size_t dimension)
 Construct a variational distribution of the specified dimensionality with a zero mean and zero log standard deviation (unit standard deviation). More...
 
 normal_meanfield (const Eigen::VectorXd &cont_params)
 Construct a variational distribution with the specified mean vector and zero log standard deviation (unit standard deviation). More...
 
 normal_meanfield (const Eigen::VectorXd &mu, const Eigen::VectorXd &omega)
 Construct a variational distribution with the specified mean and log standard deviation vectors. More...
 
int dimension () const
 Return the dimensionality of the approximation. More...
 
const Eigen::VectorXd & mu () const
 Return the mean vector. More...
 
const Eigen::VectorXd & omega () const
 Return the log standard deviation vector. More...
 
void set_mu (const Eigen::VectorXd &mu)
 Set the mean vector to the specified value. More...
 
void set_omega (const Eigen::VectorXd &omega)
 Set the log standard deviation vector to the specified value. More...
 
void set_to_zero ()
 Sets the mean and log standard deviation vector for this approximation to zero. More...
 
normal_meanfield square () const
 Return a new mean field approximation resulting from squaring the entries in the mean and log standard deviation. More...
 
normal_meanfield sqrt () const
 Return a new mean field approximation resulting from taking the square root of the entries in the mean and log standard deviation. More...
 
normal_meanfieldoperator= (const normal_meanfield &rhs)
 Return this approximation after setting its mean vector and Cholesky factor for covariance to the values given by the specified approximation. More...
 
normal_meanfieldoperator+= (const normal_meanfield &rhs)
 Add the mean and Cholesky factor of the covariance matrix of the specified approximation to this approximation. More...
 
normal_meanfieldoperator/= (const normal_meanfield &rhs)
 Return this approximation after elementwise division by the specified approximation's mean and log standard deviation vectors. More...
 
normal_meanfieldoperator+= (double scalar)
 Return this approximation after adding the specified scalar to each entry in the mean and log standard deviation vectors. More...
 
normal_meanfieldoperator*= (double scalar)
 Return this approximation after multiplying by the specified scalar to each entry in the mean and log standard deviation vectors. More...
 
const Eigen::VectorXd & mean () const
 Returns the mean vector for this approximation. More...
 
double entropy () const
 Return the entropy of the 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
 Assign a draw from this mean field approximation to the specified vector using the specified random number generator. More...
 
template<class M , class BaseRNG >
void calc_grad (normal_meanfield &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 log-std vector (omega) 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 mean-field (diagonal covariance) multivariate normal distribution.

Definition at line 33 of file normal_meanfield.hpp.

Constructor & Destructor Documentation

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

Construct a variational distribution of the specified dimensionality with a zero mean and zero log standard deviation (unit standard deviation).

Parameters
[in]dimensionDimensionality of distribution.

Definition at line 58 of file normal_meanfield.hpp.

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

Construct a variational distribution with the specified mean vector and zero log standard deviation (unit standard deviation).

Parameters
[in]cont_paramsMean vector.

Definition at line 71 of file normal_meanfield.hpp.

stan::variational::normal_meanfield::normal_meanfield ( const Eigen::VectorXd &  mu,
const Eigen::VectorXd &  omega 
)
inline

Construct a variational distribution with the specified mean and log standard deviation vectors.

Parameters
[in]muMean vector.
[in]omegaLog standard deviation vector.
Exceptions
std::domain_errorIf the sizes of mean and log standard deviation vectors are different, or if either contains a not-a-number value.

Definition at line 87 of file normal_meanfield.hpp.

Member Function Documentation

template<class M , class BaseRNG >
void stan::variational::normal_meanfield::calc_grad ( normal_meanfield 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 log-std vector (omega) 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_gradParameters to store "blackbox" gradient
[in]mModel.
[in]cont_paramsContinuous parameters.
[in]n_monte_carlo_gradNumber of samples 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 376 of file normal_meanfield.hpp.

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

Return the dimensionality of the approximation.

Definition at line 102 of file normal_meanfield.hpp.

double stan::variational::normal_meanfield::entropy ( ) const
inline

Return the entropy of the approximation.

The entropy is defined by 0.5 * dim * (1+log2pi) + 0.5 * log det diag(sigma^2) = 0.5 * dim * (1+log2pi) + sum(log(sigma)) = 0.5 * dim * (1+log2pi) + sum(omega)

Returns
Entropy of this approximation.

Definition at line 311 of file normal_meanfield.hpp.

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

Returns the mean vector for this approximation.

See: mu().

Returns
Mean vector for this approximation.

Definition at line 297 of file normal_meanfield.hpp.

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

Return the mean vector.

Definition at line 107 of file normal_meanfield.hpp.

const Eigen::VectorXd& stan::variational::normal_meanfield::omega ( ) const
inline

Return the log standard deviation vector.

Definition at line 112 of file normal_meanfield.hpp.

normal_meanfield& stan::variational::normal_meanfield::operator*= ( double  scalar)
inline

Return this approximation after multiplying by the specified scalar to each entry in the mean and log standard deviation vectors.

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 284 of file normal_meanfield.hpp.

normal_meanfield& stan::variational::normal_meanfield::operator+= ( const normal_meanfield 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 log standard deviation vectors.
Returns
This approximation after adding the specified approximation.
Exceptions
std::domain_errorIf the size of the specified approximation does not match the size of this approximation.

Definition at line 221 of file normal_meanfield.hpp.

normal_meanfield& stan::variational::normal_meanfield::operator+= ( double  scalar)
inline

Return this approximation after adding the specified scalar to each entry in the mean and log standard deviation vectors.

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 266 of file normal_meanfield.hpp.

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

Return this approximation after elementwise division by the specified approximation's mean and log standard deviation vectors.

Parameters
[in]rhsApproximation from which to gather the mean and log standard deviation vectors.
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 244 of file normal_meanfield.hpp.

normal_meanfield& stan::variational::normal_meanfield::operator= ( const normal_meanfield 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 log standard deviation vectors.
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 199 of file normal_meanfield.hpp.

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

Assign a draw from this mean field approximation to the specified vector using the specified random number generator.

Template Parameters
BaseRNGClass of random number generator.
Parameters
[in]rngBase random number generator.
[in,out]etaVector to which the draw is assigned; must already be properly sized.
Exceptions
std::range_errorIf the index is out of range.

Definition at line 350 of file normal_meanfield.hpp.

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

Set the mean vector to the specified value.

Parameters
[in]muMean vector.
Exceptions
std::domain_errorIf the mean vector's size does not match this approximation's dimensionality, or if it contains not-a-number values.

Definition at line 122 of file normal_meanfield.hpp.

void stan::variational::normal_meanfield::set_omega ( const Eigen::VectorXd &  omega)
inline

Set the log standard deviation vector to the specified value.

Parameters
[in]omegaLog standard deviation vector.
Exceptions
std::domain_errorIf the log standard deviation vector's size does not match this approximation's dimensionality, or if it contains not-a-number values.

Definition at line 142 of file normal_meanfield.hpp.

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

Sets the mean and log standard deviation vector for this approximation to zero.

Definition at line 157 of file normal_meanfield.hpp.

normal_meanfield stan::variational::normal_meanfield::sqrt ( ) const
inline

Return a new mean field approximation resulting from taking the square root of the entries in the mean and log standard deviation.

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 183 of file normal_meanfield.hpp.

normal_meanfield stan::variational::normal_meanfield::square ( ) const
inline

Return a new mean field approximation resulting from squaring the entries in the mean and log standard deviation.

The new approximation does not hold any references to this approximation.

Definition at line 168 of file normal_meanfield.hpp.

Eigen::VectorXd stan::variational::normal_meanfield::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) = sigma * eta + mu = exp(omega) * 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 328 of file normal_meanfield.hpp.


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

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