24 "regression_type", rtype,
"The type of regression to perform.");
26 "Maximum polynomial degree to use for the regression.");
27 params.
addParam<Real>(
"penalty", 0.0,
"Penalty for Ridge regularization.");
34 _predictor_row(getPredictorData()),
35 _regression_type(getParam<
MooseEnum>(
"regression_type")),
36 _penalty(getParam<Real>(
"penalty")),
37 _coeff(declareModelData<
std::vector<
std::vector<Real>>>(
"_coeff")),
39 declareModelData<unsigned
int>(
"_max_degree", getParam<unsigned
int>(
"max_degree"))),
40 _power_matrix(declareModelData<
std::vector<
std::vector<unsigned
int>>>(
42 StochasticTools::MultiDimPolynomialGenerator::generateTuple(_n_dims, _max_degree + 1))),
43 _n_poly_terms(_power_matrix.size()),
44 _matrix(_n_poly_terms, _n_poly_terms),
45 _rhs(1, DenseVector<Real>(_n_poly_terms, 0.0)),
56 mooseError(
"Number of data points must be greater than the number of terms in the polynomial.");
72 for (
unsigned int r = 0; r <
_rhs.size(); ++r)
77 calc->initializeCalculator();
94 for (
unsigned int r =
_rhs.size(); r <
_rvecval->size(); ++r)
103 for (
unsigned int ii = 0; ii <
_n_dims; ++ii)
109 for (
unsigned int jj = 0; jj <
_n_dims; ++jj)
112 _matrix(i, j) += i_value * j_value;
116 for (
unsigned int c = i * 3;
c < (i + 1) * 3; ++
c)
122 for (
unsigned int r = 0; r <
_rvecval->size(); ++r)
123 _rhs[r](i) += i_value * (*_rvecval)[r];
129 for (
unsigned int r = 0; r <
_rvecval->size(); ++r)
142 unsigned int nrval =
_rhs.size();
144 for (
unsigned int r =
_rhs.size(); r < nrval; ++r)
152 for (
auto & it :
_rhs)
160 calc->finalizeCalculator(
true);
170 sig[i] = i > 0 ?
_calculators[3 * i + 1]->getValue() : 1.0;
175 const Real n = sum_pf[0];
180 _matrix(i, j) -= (
mu[j] * sum_pf[i] +
mu[i] * sum_pf[j]);
182 _matrix(i, j) /= (sig[i] * sig[j]);
184 for (
unsigned int r = 0; r <
_rhs.size(); ++r)
188 DenseVector<Real> sol;
191 for (
unsigned int r = 0; r <
_rhs.size(); ++r)
194 _coeff[r] = sol.get_values();
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
registerMooseObject("StochasticToolsApp", PolynomialRegressionTrainer)
void ErrorVector unsigned int
void mooseError(Args &&... args) const
void mooseWarning(Args &&... args) const
const unsigned int & _max_degree
Maximum polynomial degree, limiting the sum of constituent polynomial degrees.
std::vector< Real > _r_sum
Calculator used to sum response values.
const Real & _penalty
The penalty parameter for Ridge regularization.
std::vector< std::unique_ptr< RealCalculator > > _calculators
Calculators used in standardizing polynomial features.
const MooseEnum & _regression_type
Types for the polynomial regression.
const std::vector< std::vector< unsigned int > > & _power_matrix
Matirx co containing the touples of the powers for each term.
const unsigned int _n_poly_terms
Number of terms in the polynomial expression.
std::vector< std::vector< Real > > & _coeff
Coefficients of regression model.
static InputParameters validParams()
virtual void train() override
std::vector< DenseVector< Real > > _rhs
virtual void postTrain() override
DenseMatrix< Real > _matrix
PolynomialRegressionTrainer(const InputParameters ¶meters)
const std::vector< Real > & _predictor_row
Data from the current predictor row.
virtual void preTrain() override
dof_id_type getNumberOfRows() const
This is the main trainer base class.
const std::vector< Real > * _rvecval
Vector response value.
const Real * _rval
Response value.
static InputParameters validParams()
unsigned int _n_dims
Dimension of predictor data - either _sampler.getNumberOfCols() or _pvals.size() + _pcols....
std::vector< T > & get_values()
void resize(const unsigned int new_m, const unsigned int new_n)
void lu_solve(const DenseVector< T > &b, DenseVector< T > &x)
virtual void zero() override final