MUQ  0.4.3
muq::Modeling::Distribution Class Reference

#include <Distribution.h>

Inheritance diagram for muq::Modeling::Distribution:

Detailed Description

Definition at line 18 of file Distribution.h.

Public Member Functions

 Distribution (unsigned int varSizeIn, Eigen::VectorXi const &hyperSizesIn=Eigen::VectorXi())
 
virtual ~Distribution ()=default
 
virtual double LogDensity (ref_vector< Eigen::VectorXd > const &inputs)
 Evaluate the log-density. More...
 
virtual double LogDensity (std::vector< Eigen::VectorXd > const &inputs)
 
 VARIADIC_TO_REFVECTOR (LogDensity, Eigen::VectorXd, double)
 
virtual Eigen::VectorXd GradLogDensity (unsigned int wrt, std::vector< Eigen::VectorXd > const &inputs)
 
virtual Eigen::VectorXd GradLogDensity (unsigned int wrt, ref_vector< Eigen::VectorXd > const &inputs)
 
template<typename... Args>
Eigen::VectorXd GradLogDensity (unsigned int wrt, Args... args)
 
virtual Eigen::VectorXd ApplyLogDensityHessian (unsigned int const inWrt1, unsigned int const inWrt2, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &vec)
 
virtual Eigen::VectorXd ApplyLogDensityHessian (unsigned int const inWrt1, unsigned int const inWrt2, std::vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &vec)
 
Eigen::VectorXd Sample (ref_vector< Eigen::VectorXd > const &inputs)
 Sample the distribution. More...
 
Eigen::VectorXd Sample (std::vector< Eigen::VectorXd > const &inputs)
 
Eigen::VectorXd Sample ()
 Sample the distribution with no inputs. More...
 
 VARIADIC_TO_REFVECTOR (Sample, Eigen::VectorXd, Eigen::VectorXd)
 
std::shared_ptr< DensityAsDensity ()
 Returns a density built from this distribution. More...
 
std::shared_ptr< RandomVariableAsVariable ()
 Returns a random variable built from this distribution. More...
 

Public Attributes

const unsigned int varSize
 
const Eigen::VectorXi hyperSizes
 

Friends

class Density
 
class RandomVariable
 

Constructor & Destructor Documentation

◆ Distribution()

muq::Modeling::Distribution::Distribution ( unsigned int  varSizeIn,
Eigen::VectorXi const &  hyperSizesIn = Eigen::VectorXi() 
)
inline

Definition at line 23 of file Distribution.h.

◆ ~Distribution()

virtual muq::Modeling::Distribution::~Distribution ( )
virtualdefault

Member Function Documentation

◆ ApplyLogDensityHessian() [1/2]

Eigen::VectorXd Distribution::ApplyLogDensityHessian ( unsigned int const  inWrt1,
unsigned int const  inWrt2,
ref_vector< Eigen::VectorXd > const &  input,
Eigen::VectorXd const &  vec 
)
virtual

◆ ApplyLogDensityHessian() [2/2]

virtual Eigen::VectorXd muq::Modeling::Distribution::ApplyLogDensityHessian ( unsigned int const  inWrt1,
unsigned int const  inWrt2,
std::vector< Eigen::VectorXd > const &  input,
Eigen::VectorXd const &  vec 
)
inlinevirtual

Definition at line 56 of file Distribution.h.

References ApplyLogDensityHessian(), and ToRefVector().

◆ ApplyLogDensityHessianImpl()

Eigen::VectorXd Distribution::ApplyLogDensityHessianImpl ( unsigned int  wrt1,
unsigned int  wrt2,
ref_vector< Eigen::VectorXd > const &  inputs,
Eigen::VectorXd const &  vec 
)
protectedvirtual

◆ AsDensity()

std::shared_ptr< Density > Distribution::AsDensity ( )

Returns a density built from this distribution.

The distribution class allows users to both evaluate the density corresponding to a probability distribution and draw a sample of the corresponding random variable. Both of these actions are supported through the Evaluate function, where the first input to Evaluate specifies what action to perform: evaluate the density or sample the RV. However, sometimes we only want to focus on the density part of the distribution. This function returns a Density object that only supports evaluting the log density and does not require the extra input specifying what type of action to perform.

For example,

std::shared_ptr<Distribution> dist = std::make_shared<Gaussian>(mu,cov);
Eigen::VectorXd x;
// ... initialize the point x
// To obtain the density through Evaluate, we need to call
boost::any densVal = dist->Evaluate(Distribution::Mode::EvaluateLogDensity, x);
// With Density however, we don't need to add the additional flag
boost::any densVal2 = dist->AsDensity()->Evaluate(x);
// or, analogously
std::shared_ptr<Density> dens = dist->AsDensity();
boost::any densVal3 = dens->Evaluate(x);

Definition at line 9 of file Distribution.cpp.

◆ AsVariable()

std::shared_ptr< RandomVariable > Distribution::AsVariable ( )

Returns a random variable built from this distribution.

The distribution class allows users to both evaluate the density corresponding to a probability distribution and draw a sample of the corresponding random variable. Both of these actions are supported through the Evaluate function, where the first input to Evaluate specifies what action to perform: evaluate the density or sample the RV. However, sometimes we only want to focus on the random variable part (i.e., the "Sample" function) of the distribution. This function returns a RandomVariable object that only supports drawing realizations of the distribution, not evaluting the density. Because the RandomVariable only does one thing, it does not require the extra input specifying what type of action to perform.

For example,

std::shared_ptr<Distribution> dist = std::make_shared<Gaussian>(mu,cov);
Eigen::VectorXd x;
// ... initialize the point x
// To obtain a sample, we need to call
boost::any sample = dist->Evaluate(Distribution::Mode::SampleDistribution, x);
// With the RandomVariable class however, we don't need to add the additional flag
boost::any sample2 = dist->AsVariable()->Evaluate(x);
// or, analogously
std::shared_ptr<RandomVariable> rv = dist->AsVariable();
boost::any sample3 = rv->Evaluate(x);

Definition at line 14 of file Distribution.cpp.

◆ GradLogDensity() [1/4]

template<typename... Args>
Eigen::VectorXd muq::Modeling::Distribution::GradLogDensity ( unsigned int  wrt,
Args...  args 
)
inline

Definition at line 44 of file Distribution.h.

References GradLogDensity().

◆ GradLogDensity() [2/4]

template<typename... Args>
Eigen::VectorXd muq::Modeling::Distribution::GradLogDensity ( unsigned int  wrt,
ref_vector< Eigen::VectorXd > &  inputs,
Eigen::VectorXd const &  in,
Args...  args 
)
inlineprivate

Definition at line 180 of file Distribution.h.

References GradLogDensity().

◆ GradLogDensity() [3/4]

Eigen::VectorXd Distribution::GradLogDensity ( unsigned int  wrt,
ref_vector< Eigen::VectorXd > const &  inputs 
)
virtual

Reimplemented in muq::Modeling::Gamma.

Definition at line 44 of file Distribution.cpp.

References GradLogDensityImpl().

◆ GradLogDensity() [4/4]

virtual Eigen::VectorXd muq::Modeling::Distribution::GradLogDensity ( unsigned int  wrt,
std::vector< Eigen::VectorXd > const &  inputs 
)
inlinevirtual

◆ GradLogDensityImpl()

Eigen::VectorXd Distribution::GradLogDensityImpl ( unsigned int  wrt,
ref_vector< Eigen::VectorXd > const &  inputs 
)
protectedvirtual

◆ LogDensity() [1/2]

double Distribution::LogDensity ( ref_vector< Eigen::VectorXd > const &  inputs)
virtual

Evaluate the log-density.

If known, the log-density should be implemented by a child in the LogDensityImpl class.

Parameters
[in]inputsthe vector of inputs to the log-density
Returns
The log density

Definition at line 31 of file Distribution.cpp.

References LogDensityImpl().

Referenced by muq::Modeling::DensityBase::EvaluateImpl(), GradLogDensityImpl(), muq::SamplingAlgorithms::InverseGammaProposal::LogDensity(), and muq::SamplingAlgorithms::SMMALAProposal::LogDensity().

◆ LogDensity() [2/2]

virtual double muq::Modeling::Distribution::LogDensity ( std::vector< Eigen::VectorXd > const &  inputs)
inlinevirtual

Definition at line 36 of file Distribution.h.

References LogDensity(), and ToRefVector().

Referenced by LogDensity().

◆ LogDensityImpl()

virtual double muq::Modeling::Distribution::LogDensityImpl ( ref_vector< Eigen::VectorXd > const &  inputs)
inlineprotectedvirtual

Implement the log-density.

If known, the log-density should be implemented by a child. If it is not overridden then the default behavior is to return negative infinity (-1.0*std::numeric_limits<double>::infinity()).

Parameters
[in]inputsthe vector of inputs to the log-density
Returns
The log density

Reimplemented in muq::Modeling::UniformBox, muq::Modeling::RandomVariable, muq::Modeling::PyDistribution, muq::Modeling::MixtureDistribution, muq::Modeling::InverseGamma, muq::Modeling::GaussianBase, muq::Modeling::Gamma, muq::Modeling::DensityProduct, and muq::Modeling::Density.

Definition at line 156 of file Distribution.h.

Referenced by LogDensity().

◆ Sample() [1/3]

Eigen::VectorXd Distribution::Sample ( )

Sample the distribution with no inputs.

Allows the user to call Sample without any inputs

Returns
A sample

Definition at line 40 of file Distribution.cpp.

◆ Sample() [2/3]

Eigen::VectorXd Distribution::Sample ( ref_vector< Eigen::VectorXd > const &  inputs)

Sample the distribution.

Calls SampleImpl, the default behavior is to return boost::none

Parameters
[in]inputsthe vector of inputs to the log-density
Returns
A sample

Definition at line 36 of file Distribution.cpp.

References SampleImpl().

Referenced by muq::SamplingAlgorithms::InverseGammaProposal::Sample(), and muq::SamplingAlgorithms::SMMALAProposal::Sample().

◆ Sample() [3/3]

Eigen::VectorXd muq::Modeling::Distribution::Sample ( std::vector< Eigen::VectorXd > const &  inputs)
inline

Definition at line 69 of file Distribution.h.

References Sample(), and ToRefVector().

Referenced by Sample().

◆ SampleImpl()

virtual Eigen::VectorXd muq::Modeling::Distribution::SampleImpl ( ref_vector< Eigen::VectorXd > const &  inputs)
inlineprotectedvirtual

Sample the distribution.

Should be overwritten by a child. The default behavior is to return boost::none

Reimplemented in muq::Modeling::UniformBox, muq::Modeling::RandomVariable, muq::Modeling::PyDistribution, muq::Modeling::MixtureDistribution, muq::Modeling::InverseGamma, muq::Modeling::GaussianBase, muq::Modeling::Gamma, and muq::Modeling::Density.

Definition at line 170 of file Distribution.h.

Referenced by Sample().

◆ ToRefVector()

ref_vector< const Eigen::VectorXd > Distribution::ToRefVector ( std::vector< Eigen::VectorXd > const &  anyVec) const
protected

Definition at line 19 of file Distribution.cpp.

Referenced by ApplyLogDensityHessian(), GradLogDensity(), LogDensity(), and Sample().

◆ VARIADIC_TO_REFVECTOR() [1/2]

muq::Modeling::Distribution::VARIADIC_TO_REFVECTOR ( LogDensity  ,
Eigen::VectorXd  ,
double   
)

◆ VARIADIC_TO_REFVECTOR() [2/2]

muq::Modeling::Distribution::VARIADIC_TO_REFVECTOR ( Sample  ,
Eigen::VectorXd  ,
Eigen::VectorXd   
)

Friends And Related Function Documentation

◆ Density

friend class Density
friend

Definition at line 20 of file Distribution.h.

◆ RandomVariable

friend class RandomVariable
friend

Definition at line 21 of file Distribution.h.

Member Data Documentation

◆ hyperSizes

const Eigen::VectorXi muq::Modeling::Distribution::hyperSizes

◆ varSize

const unsigned int muq::Modeling::Distribution::varSize

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