MUQ  0.4.3
muq::Modeling::UniformBox Class Reference

Defines a normalized uniform distribution over a bounded rectangular domain. More...

#include <UniformBox.h>

Inheritance diagram for muq::Modeling::UniformBox:

Detailed Description

Defines a normalized uniform distribution over a bounded rectangular domain.

This class defines a uniform distribution between coordinate-aligned lower and upper bounds. Let \(\theta \) denote the input random variable with components \(\theta_i\) for \(i\in \{1,2,\ldots, D\}\), let \(L_i \) denote the lower bound for component \(i\), and let \(U_i\) denote the upper bound on \(\theta_i \). Then, this class implements

\[ \pi(\theta) = \prod \pi_i(\theta_i), \]

where

\[ \pi_i(\theta_i) = U\left[ L_i, U_i \right] = \left\{ \begin{array}{ll}\frac{1}{U_i-L_i} & L_i\leq x_i \leq U_i \\ 0 & \text{Otherwise} \end{array}\right. . \]

This class can be initialized in three ways: with a matrix containing L_i and U_i, using std::pair<double,double> to collect the lower and upper bounds, and directly with a linear vector of doubles with entries that alternate between lower and upper bounds. The following code snippets are all equivalent approaches for constructing the uniform distribution.

Construct from an Eigen::Matrix

int dim = 4;
Eigen::MatrixXd bounds(dim,2);
bounds << 0.0, 1.0,
0.5, 0.75,
1.0, 2.0,
4.0, 10.0;
auto dist = std::make_shared<UniformBox>(bounds);

Construct from a std::vector of pairs

int dim = 4;
std::vector<std::pair<double, double>> bounds(dim);
bounds.at(0) = std::make_pair(0.0, 1.0);
bounds.at(1) = std::make_pair(0.5, 0.75);
bounds.at(2) = std::make_pair(1.0, 2.0);
bounds.at(3) = std::make_pair(4.0, 10.0);
auto dist = std::make_shared<UniformBox>(bounds);

Construct directly from lower and upper pairs

int dim = 4;
std::pair<double, double> b1 = std::make_pair(0.0, 1.0);
std::pair<double, double> b2 = std::make_pair(0.5, 0.75);
std::pair<double, double> b3 = std::make_pair(1.0, 2.0);
std::pair<double, double> b4 = std::make_pair(4.0, 10.0);
auto dist = std::make_shared<UniformBox>(b1, b2, b3, b4);

Construct with a linear vector of doubles

int dim = 4;
std::vector<double> bounds(2*dim);
bounds.at(0) = 0.0;
bounds.at(1) = 1.0;
bounds.at(2) = 0.5;
bounds.at(3) = 0.75;
bounds.at(4) = 1.0;
bounds.at(5) = 2.0;
bounds.at(6) = 4.0;
bounds.at(7) = 10.0;
auto dist = std::make_shared<UniformBox>(bounds);

Construct directly from doubles

auto dist = std::make_shared<UniformBox>(0.0, 1.0, 0.5, 0.75, 1.0, 2.0, 4.0, 10.0);

Definition at line 83 of file UniformBox.h.

Public Member Functions

virtual ~UniformBox ()=default
 
 UniformBox (Eigen::MatrixXd const &bounds)
 Create a \(d\)-dimensional uniform distribution. More...
 
template<typename... Args>
 UniformBox (std::pair< double, double > const &pair1, Args... args)
 Create a \(d\)-dimensional uniform distribution. More...
 
 UniformBox (std::vector< std::pair< double, double >> const &pairList)
 
template<typename... Args>
 UniformBox (double lb1, double ub1, Args... args)
 
 UniformBox (std::vector< double > const &bounds)
 
- Public Member Functions inherited from muq::Modeling::Distribution
 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...
 

Additional Inherited Members

- Public Attributes inherited from muq::Modeling::Distribution
const unsigned int varSize
 
const Eigen::VectorXi hyperSizes
 

Constructor & Destructor Documentation

◆ ~UniformBox()

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

◆ UniformBox() [1/5]

UniformBox::UniformBox ( Eigen::MatrixXd const &  bounds)

Create a \(d\)-dimensional uniform distribution.

Parameters
[in]boundsA \(d\)-dimensional vector, each entry is a pair—first: lower bound in the dimension, second: upper bound in that dimension

Definition at line 8 of file UniformBox.cpp.

◆ UniformBox() [2/5]

template<typename... Args>
muq::Modeling::UniformBox::UniformBox ( std::pair< double, double > const &  pair1,
Args...  args 
)
inline

Create a \(d\)-dimensional uniform distribution.

Parameters
[in]argsThe upper/lower bound pairs (may be more than one)

Definition at line 99 of file UniformBox.h.

◆ UniformBox() [3/5]

muq::Modeling::UniformBox::UniformBox ( std::vector< std::pair< double, double >> const &  pairList)
inline

Definition at line 101 of file UniformBox.h.

◆ UniformBox() [4/5]

template<typename... Args>
muq::Modeling::UniformBox::UniformBox ( double  lb1,
double  ub1,
Args...  args 
)
inline

Definition at line 104 of file UniformBox.h.

◆ UniformBox() [5/5]

muq::Modeling::UniformBox::UniformBox ( std::vector< double > const &  bounds)
inline

Definition at line 106 of file UniformBox.h.

Member Function Documentation

◆ ComputeVolume()

double UniformBox::ComputeVolume ( Eigen::MatrixXd const &  boundsIn)
staticprivate

A matrix describing the bounding box.

A matrix that discribes the bounding box. The first row contains the lower bounds and the second row corresponds to the upper bound. Each column corresponds to a different inpu dimension.

Definition at line 15 of file UniformBox.cpp.

◆ CreateBoundsPairs()

Eigen::MatrixXd UniformBox::CreateBoundsPairs ( std::vector< std::pair< double, double >> const &  bounds)
staticprivate

Definition at line 20 of file UniformBox.cpp.

◆ LogDensityImpl()

double UniformBox::LogDensityImpl ( ref_vector< Eigen::VectorXd > const &  inputs)
overrideprivatevirtual

Evaluate the log-density.

Inputs:

  1. The state \(x\)
Returns
The log-density (either 1 or negative infinity)

Reimplemented from muq::Modeling::Distribution.

Definition at line 44 of file UniformBox.cpp.

References volume.

◆ SampleImpl()

Eigen::VectorXd UniformBox::SampleImpl ( ref_vector< Eigen::VectorXd > const &  inputs)
overrideprivatevirtual

Sample the distribution.

Reimplemented from muq::Modeling::Distribution.

Definition at line 61 of file UniformBox.cpp.

Member Data Documentation

◆ volume

const double muq::Modeling::UniformBox::volume
private

Definition at line 146 of file UniformBox.h.

Referenced by LogDensityImpl().


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