Class containing functionalitties to generate the degress of the 1D Polynomials within every term of a multi-dimensional polynomial.
More...
#include <MultiDimPolynomialGenerator.h>
|
| static std::vector< std::vector< unsigned int > > | generateTuple (unsigned int n_dims, unsigned int max_degree, bool include_bias=true) |
| | Function computing for computing _tuple Example for ndim = 3, order = 4: | 0 | 1 0 0 | 2 1 1 0 0 0 | 3 2 2 1 1 1 0 0 0 0 | | 0 | 0 1 0 | 0 1 0 2 1 0 | 0 1 0 2 1 0 3 2 1 0 | | 0 | 0 0 1 | 0 0 1 0 1 2 | 0 0 1 0 1 2 0 1 2 3 |.
|
| |
| static bool | sortTuple (const std::vector< unsigned int > &first, const std::vector< unsigned int > &second) |
| | Tuple sorter function.
|
| |
Class containing functionalitties to generate the degress of the 1D Polynomials within every term of a multi-dimensional polynomial.
Definition at line 26 of file MultiDimPolynomialGenerator.h.
◆ MultiDimPolynomialGenerator()
| StochasticTools::MultiDimPolynomialGenerator::MultiDimPolynomialGenerator |
( |
| ) |
|
|
inline |
◆ ~MultiDimPolynomialGenerator()
| StochasticTools::MultiDimPolynomialGenerator::~MultiDimPolynomialGenerator |
( |
| ) |
|
|
default |
◆ generateTuple()
| std::vector< std::vector< unsigned int > > StochasticTools::MultiDimPolynomialGenerator::generateTuple |
( |
unsigned int |
n_dims, |
|
|
unsigned int |
max_degree, |
|
|
bool |
include_bias = true |
|
) |
| |
|
static |
Function computing for computing _tuple Example for ndim = 3, order = 4: | 0 | 1 0 0 | 2 1 1 0 0 0 | 3 2 2 1 1 1 0 0 0 0 | | 0 | 0 1 0 | 0 1 0 2 1 0 | 0 1 0 2 1 0 3 2 1 0 | | 0 | 0 0 1 | 0 0 1 0 1 2 | 0 0 1 0 1 2 0 1 2 3 |.
Definition at line 16 of file MultiDimPolynomialGenerator.C.
19{
20
21 std::vector<std::vector<unsigned int>> tuple_1d(ndim);
22 for (
unsigned int d = 0;
d < ndim; ++
d)
23 {
24 tuple_1d[
d].resize(order);
25 for (unsigned int i = 0; i < order; ++i)
27 }
28
29 CartesianProduct<unsigned int> tensor_tuple(tuple_1d);
30
31
32 std::vector<std::vector<unsigned int>> tuple;
33 for (
unsigned int p = 0;
p < tensor_tuple.numRows(); ++
p)
34 {
35 std::vector<unsigned int> dorder = tensor_tuple.computeRow(
p);
36 unsigned int sum = std::accumulate(dorder.begin(), dorder.end(), 0);
37 if (sum < order)
38 tuple.push_back(dorder);
39 }
40
41 std::sort(tuple.begin(), tuple.end(),
sortTuple);
42
43 if (!include_bias)
44 tuple.erase(tuple.begin());
45
46 return tuple;
47}
◆ sortTuple()
| bool StochasticTools::MultiDimPolynomialGenerator::sortTuple |
( |
const std::vector< unsigned int > & |
first, |
|
|
const std::vector< unsigned int > & |
second |
|
) |
| |
|
static |
Tuple sorter function.
Definition at line 50 of file MultiDimPolynomialGenerator.C.
52{
53
54 if (std::accumulate(first.begin(), first.end(), 0) <
55 std::accumulate(second.begin(), second.end(), 0))
56 return true;
57 else if (std::accumulate(first.begin(), first.end(), 0) >
58 std::accumulate(second.begin(), second.end(), 0))
59 return false;
60
61
62 for (
unsigned int d = 0;
d < first.size(); ++
d)
63 {
64 if (first[
d] == second[
d])
65 continue;
66 return (first[
d] > second[
d]);
67 }
68
69 return false;
70}
Referenced by generateTuple().
The documentation for this class was generated from the following files: