https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Static Private Member Functions | Private Attributes | List of all members
StochasticTools::WeightedCartesianProduct< T, W > Class Template Reference

#include <CartesianProduct.h>

Inheritance diagram for StochasticTools::WeightedCartesianProduct< T, W >:
[legend]

Public Member Functions

 WeightedCartesianProduct (const std::vector< std::vector< T > > &items, const std::vector< std::vector< W > > &weights)
 
std::vector< W > computeWeightVector () const
 Compute complete vector of weights.
 
computeWeight (std::size_t row) const
 Compute specific weight value, given row.
 
std::vector< std::vector< T > > computeMatrix () const
 Compute the complete Cartesian product matrix.
 
std::vector< TcomputeRow (std::size_t row) const
 Compute specified row of Cartesian product matrix.
 
T computeValue (std::size_t row, std::size_t col) const
 Compute specific value, given row and column, of the Cartesian product matrix.
 
std::size_t numRows () const
 Total number of rows in the complete matrix.
 
std::size_t numCols () const
 Total number of columns in the complete matrix.
 

Protected Attributes

const std::size_t _n_rows
 Number of rows/columns.
 
const std::size_t _n_cols
 

Static Private Member Functions

static std::size_t computeRowCount (const std::vector< std::vector< T > > &items)
 Helper to compute the rows in initialization list to allow _n_rows to be const.
 

Private Attributes

const CartesianProduct< W > _weight
 Data used to create Cartesian product; use a copy because a temporary can be supplied.
 
const std::vector< std::vector< T > > _items
 Data used to create Cartesian product use a copy because a temporary can be supplied, as is the case in the CartesianProductSampler.
 
std::deque< unsigned int_denomenators
 Containers for lazy Cartesian product calculation.
 
std::deque< unsigned int_moduli
 

Detailed Description

template<class T, class W>
class StochasticTools::WeightedCartesianProduct< T, W >

Definition at line 122 of file CartesianProduct.h.

Constructor & Destructor Documentation

◆ WeightedCartesianProduct()

template<typename T , typename W >
StochasticTools::WeightedCartesianProduct< T, W >::WeightedCartesianProduct ( const std::vector< std::vector< T > > &  items,
const std::vector< std::vector< W > > &  weights 
)

Definition at line 140 of file CartesianProduct.h.

142 : CartesianProduct<T>(items), _weight(weights)
143{
144 mooseAssert(items.size() == weights.size(),
145 "The supplied items and weights must be the same size.");
146 for (std::size_t i = 0; i < items.size(); ++i)
147 mooseAssert(items[i].size() == weights[i].size(),
148 "Internal vector of the supplied items and weights must be the same size.");
149}
const CartesianProduct< W > _weight
Data used to create Cartesian product; use a copy because a temporary can be supplied.

Member Function Documentation

◆ computeMatrix()

template<typename T >
std::vector< std::vector< T > > StochasticTools::CartesianProduct< T >::computeMatrix ( ) const
inherited

Compute the complete Cartesian product matrix.

Definition at line 80 of file CartesianProduct.h.

81{
82 std::vector<std::vector<T>> output(_n_rows, std::vector<T>(_n_cols));
83 for (std::size_t row = 0; row < _n_rows; ++row)
84 for (std::size_t col = 0; col < _n_cols; ++col)
85 output[row][col] = computeValue(row, col);
86 return output;
87}
const std::size_t _n_rows
Number of rows/columns.
T computeValue(std::size_t row, std::size_t col) const
Compute specific value, given row and column, of the Cartesian product matrix.

Referenced by TEST().

◆ computeRow()

template<typename T >
std::vector< T > StochasticTools::CartesianProduct< T >::computeRow ( std::size_t  row) const
inherited

Compute specified row of Cartesian product matrix.

Definition at line 91 of file CartesianProduct.h.

92{
93 std::vector<T> output(_n_cols);
94 for (std::size_t col = 0; col < _n_cols; ++col)
95 output[col] = computeValue(row, col);
96 return output;
97}

Referenced by PolynomialQuadrature::ClenshawCurtisGrid::ClenshawCurtisGrid(), StochasticTools::MultiDimPolynomialGenerator::generateTuple(), PolynomialQuadrature::SmolyakGrid::SmolyakGrid(), and TEST().

◆ computeRowCount()

template<typename T >
std::size_t StochasticTools::CartesianProduct< T >::computeRowCount ( const std::vector< std::vector< T > > &  items)
staticprivateinherited

Helper to compute the rows in initialization list to allow _n_rows to be const.

Definition at line 110 of file CartesianProduct.h.

111{
112 std::size_t n_rows = 1;
113 for (const auto & inner : items)
114 n_rows *= inner.size();
115 return n_rows;
116}

◆ computeValue()

template<typename T >
T StochasticTools::CartesianProduct< T >::computeValue ( std::size_t  row,
std::size_t  col 
) const
inherited

Compute specific value, given row and column, of the Cartesian product matrix.

Definition at line 101 of file CartesianProduct.h.

102{
103 mooseAssert(row < _n_rows, "Row index out of range.");
104 mooseAssert(col < _n_cols, "Column index out of range.");
105 return _items[col][(row / _denomenators[col]) % _moduli[col]];
106}
std::deque< unsigned int > _moduli
const std::vector< std::vector< T > > _items
Data used to create Cartesian product use a copy because a temporary can be supplied,...
std::deque< unsigned int > _denomenators
Containers for lazy Cartesian product calculation.

Referenced by TEST().

◆ computeWeight()

template<typename T , typename W >
W StochasticTools::WeightedCartesianProduct< T, W >::computeWeight ( std::size_t  row) const

Compute specific weight value, given row.

Definition at line 163 of file CartesianProduct.h.

164{
165 std::vector<W> vec = _weight.computeRow(row);
166 return std::accumulate(vec.begin(), vec.end(), static_cast<W>(1), std::multiplies<W>());
167}
std::vector< T > computeRow(std::size_t row) const
Compute specified row of Cartesian product matrix.

Referenced by PolynomialQuadrature::ClenshawCurtisGrid::ClenshawCurtisGrid(), and TEST().

◆ computeWeightVector()

template<typename T , typename W >
std::vector< W > StochasticTools::WeightedCartesianProduct< T, W >::computeWeightVector ( ) const

Compute complete vector of weights.

Definition at line 153 of file CartesianProduct.h.

154{
155 std::vector<W> output(this->_n_rows);
156 for (std::size_t i = 0; i < output.size(); ++i)
157 output[i] = computeWeight(i);
158 return output;
159}
W computeWeight(std::size_t row) const
Compute specific weight value, given row.

Referenced by TEST().

◆ numCols()

template<class T >
std::size_t StochasticTools::CartesianProduct< T >::numCols ( ) const
inlineinherited

Total number of columns in the complete matrix.

Definition at line 42 of file CartesianProduct.h.

42{ return _n_cols; }

Referenced by TEST(), and TEST().

◆ numRows()

template<class T >
std::size_t StochasticTools::CartesianProduct< T >::numRows ( ) const
inlineinherited

Member Data Documentation

◆ _denomenators

template<class T >
std::deque<unsigned int> StochasticTools::CartesianProduct< T >::_denomenators
privateinherited

Containers for lazy Cartesian product calculation.

Definition at line 55 of file CartesianProduct.h.

Referenced by StochasticTools::CartesianProduct< T >::CartesianProduct().

◆ _items

template<class T >
const std::vector<std::vector<T> > StochasticTools::CartesianProduct< T >::_items
privateinherited

Data used to create Cartesian product use a copy because a temporary can be supplied, as is the case in the CartesianProductSampler.

Definition at line 52 of file CartesianProduct.h.

Referenced by StochasticTools::CartesianProduct< T >::CartesianProduct().

◆ _moduli

template<class T >
std::deque<unsigned int> StochasticTools::CartesianProduct< T >::_moduli
privateinherited

◆ _n_cols

template<class T >
const std::size_t StochasticTools::CartesianProduct< T >::_n_cols
protectedinherited

Definition at line 47 of file CartesianProduct.h.

Referenced by StochasticTools::CartesianProduct< T >::numCols().

◆ _n_rows

template<class T >
const std::size_t StochasticTools::CartesianProduct< T >::_n_rows
protectedinherited

Number of rows/columns.

Definition at line 46 of file CartesianProduct.h.

Referenced by StochasticTools::CartesianProduct< T >::numRows().

◆ _weight

template<class T , class W >
const CartesianProduct<W> StochasticTools::WeightedCartesianProduct< T, W >::_weight
private

Data used to create Cartesian product; use a copy because a temporary can be supplied.

Definition at line 136 of file CartesianProduct.h.


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