44template <
typename Variable, index_type PolynomialDegree>
53template <base::concepts::real_scalar Variable, index_type PolynomialDegree>
54 requires(PolynomialDegree >= 0)
74 template <base::concepts::dense_matrix_of<Variable> Matrix>
76 const std::vector<Variable>& variables, Matrix& matrix)
const {
77 const auto num_variables =
static_cast<index_type>(variables.size());
79 "At least (PolynomialDegree + 2) variables must be given.");
81 matrix.resize(num_variables, PolynomialDegree + 1);
84 matrix.col(0) = Eigen::MatrixX<Variable>::Constant(
85 num_variables, 1,
static_cast<Variable
>(1));
87 for (
index_type degree = 1; degree <= PolynomialDegree; ++degree) {
88 for (
index_type i = 0; i < num_variables; ++i) {
90 matrix(i, degree) =
static_cast<Variable
>(
91 pow(variables[
static_cast<std::size_t
>(i)], degree));
104 const Eigen::VectorX<Variable>& coeffs)
const -> Variable {
106 "Size of coefficients must be (PolynomialDegree + 1).");
109 auto value = coeffs(0);
111 for (
index_type degree = 1; degree <= PolynomialDegree; ++degree) {
114 coeffs(degree) *
static_cast<Variable
>(pow(variable, degree));
127template <base::concepts::dense_vector Variable, index_type PolynomialDegree>
128 requires(PolynomialDegree >= 0)
141 PolynomialDegree < 2,
"Currently, up to 1 degree is supported.");
143 if constexpr (PolynomialDegree == 1) {
144 num_patterns += num_dimensions;
147 degrees_.resize(num_patterns, num_dimensions);
150 for (
index_type d = 0; d < num_dimensions; ++d) {
154 if constexpr (PolynomialDegree >= 1) {
156 degrees_.bottomRows(num_dimensions) =
157 Eigen::MatrixX<index_type>::Identity(
158 num_dimensions, num_dimensions);
169 template <base::concepts::dense_matrix_of<scalar_type> Matrix>
171 const std::vector<Variable>& variables, Matrix& matrix)
const {
172 const auto num_variables =
static_cast<index_type>(variables.size());
174 const index_type num_dimensions = variables.front().size();
176 const index_type num_patterns = degrees_.rows();
177 matrix.resize(num_variables, num_patterns);
178 for (
index_type i = 0; i < num_variables; ++i) {
179 const auto& variable = variables[
static_cast<std::size_t
>(i)];
180 for (
index_type p = 0; p < num_patterns; ++p) {
182 for (
index_type d = 0; d < num_dimensions; ++d) {
183 if (degrees_(p, d) > 0) {
185 value *= pow(variable(d), degrees_(p, d));
188 matrix(i, p) = value;
201 const Eigen::VectorX<scalar_type>& coeffs)
const ->
scalar_type {
202 const index_type num_dimensions = variable.size();
204 const index_type num_patterns = degrees_.rows();
206 "Size of coefficients must be the same as the number of patterns.");
209 for (
index_type p = 0; p < num_patterns; ++p) {
211 for (
index_type d = 0; d < num_dimensions; ++d) {
212 if (degrees_(p, d) > 0) {
214 current_term *= pow(variable(d), degrees_(p, d));
217 value += current_term;
225 Eigen::Matrix<index_type, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
auto evaluate_polynomial_for_variable(Variable variable, const Eigen::VectorX< scalar_type > &coeffs) const -> scalar_type
Evaluate a polynomial for a variable.
void prepare(index_type num_dimensions)
Prepare internal parameters.
void compute_polynomial_term_matrix(const std::vector< Variable > &variables, Matrix &matrix) const
Compute a matrix of polynomial terms.
auto evaluate_polynomial_for_variable(Variable variable, const Eigen::VectorX< Variable > &coeffs) const -> Variable
Evaluate a polynomial for a variable.
typename Variable::Scalar scalar_type
Type of scalars.
Class to calculate polynomials used with RBF interpolation.
Definition of dense_matrix_of concept.
Definition of dense_vector concept.
Definition of exceptions.
Definition of index_type type.
Definition of macros for logging.
std::ptrdiff_t index_type
Type of indices in this library.
Namespace of RBF interpolation.
Definition of NUM_COLLECT_PRECONDITION macro.
#define NUM_COLLECT_PRECONDITION(CONDITION,...)
Check whether a precondition is satisfied and throw an exception if not.
Definition of real_scalar concept.