https://mooseframework.inl.gov
Public Member Functions | Protected Attributes | 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. More...
 
computeWeight (std::size_t row) const
 Compute specific weight value, given row. More...
 
std::vector< std::vector< T > > computeMatrix () const
 Compute the complete Cartesian product matrix. More...
 
std::vector< TcomputeRow (std::size_t row) const
 Compute specified row of Cartesian product matrix. More...
 
T computeValue (std::size_t row, std::size_t col) const
 Compute specific value, given row and column, of the Cartesian product matrix. More...
 
std::size_t numRows () const
 Total number of rows in the complete matrix. More...
 
std::size_t numCols () const
 Total number of columns in the complete matrix. More...
 

Protected Attributes

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

Private Attributes

const CartesianProduct< W > _weight
 Data used to create Cartesian product; use a copy because a temporary can be supplied. More...
 

Detailed Description

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

Definition at line 124 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 142 of file CartesianProduct.h.

144  : CartesianProduct<T>(items), _weight(weights)
145 {
146  mooseAssert(items.size() == weights.size(),
147  "The supplied items and weights must be the same size.");
148  for (std::size_t i = 0; i < items.size(); ++i)
149  mooseAssert(items[i].size() == weights[i].size(),
150  "Internal vector of the supplied items and weights must be the same size.");
151 }
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 82 of file CartesianProduct.h.

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

◆ 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 93 of file CartesianProduct.h.

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

94 {
95  std::vector<T> output(_n_cols);
96  for (std::size_t col = 0; col < _n_cols; ++col)
97  output[col] = computeValue(row, col);
98  return output;
99 }
T computeValue(std::size_t row, std::size_t col) const
Compute specific value, given row and column, of the Cartesian product matrix.

◆ 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 103 of file CartesianProduct.h.

104 {
105  mooseAssert(row < _n_rows, "Row index out of range.");
106  mooseAssert(col < _n_cols, "Column index out of range.");
107  return _items[col][(row / _denomenators[col]) % _moduli[col]];
108 }
std::deque< unsigned int > _denomenators
Containers for lazy Cartesian product calculation.
std::deque< unsigned int > _moduli
const std::size_t _n_rows
Number of rows/columns.
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.

◆ 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 165 of file CartesianProduct.h.

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

166 {
167  std::vector<W> vec = _weight.computeRow(row);
168  return std::accumulate(vec.begin(), vec.end(), static_cast<W>(1), std::multiplies<W>());
169 }
const CartesianProduct< W > _weight
Data used to create Cartesian product; use a copy because a temporary can be supplied.
std::vector< T > computeRow(std::size_t row) const
Compute specified row of Cartesian product matrix.

◆ computeWeightVector()

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

Compute complete vector of weights.

Definition at line 155 of file CartesianProduct.h.

Referenced by TEST().

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

◆ numCols()

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

Total number of columns in the complete matrix.

Definition at line 44 of file CartesianProduct.h.

Referenced by TEST().

44 { return _n_cols; }

◆ numRows()

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

Total number of rows in the complete matrix.

Definition at line 41 of file CartesianProduct.h.

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

41 { return _n_rows; }
const std::size_t _n_rows
Number of rows/columns.

Member Data Documentation

◆ _n_cols

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

Definition at line 49 of file CartesianProduct.h.

◆ _n_rows

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

Number of rows/columns.

Definition at line 48 of file CartesianProduct.h.

◆ _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 138 of file CartesianProduct.h.


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