https://mooseframework.inl.gov
PolynomialRegressionSurrogate.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 
13 
16 {
18  params.addClassDescription("Evaluates polynomial regression model with coefficients computed "
19  "from PolynomialRegressionTrainer.");
20  return params;
21 }
22 
24  : SurrogateModel(parameters),
25  _coeff(getModelData<std::vector<std::vector<Real>>>("_coeff")),
26  _power_matrix(getModelData<std::vector<std::vector<unsigned int>>>("_power_matrix")),
27  _max_degree(getModelData<unsigned int>("_max_degree"))
28 {
29 }
30 
31 Real
32 PolynomialRegressionSurrogate::evaluate(const std::vector<Real> & x) const
33 {
34  // Check whether input point has same dimensionality as training data
35  mooseAssert(_power_matrix[0].size() == x.size(),
36  "Input point does not match dimensionality of training data.");
37 
38  Real val(0.0);
39  for (unsigned int i = 0; i < _power_matrix.size(); ++i)
40  {
41  Real tmp_val(1.0);
42  for (unsigned int j = 0; j < _power_matrix[i].size(); ++j)
43  tmp_val *= MathUtils::pow(x[j], _power_matrix[i][j]);
44  val += _coeff[0][i] * tmp_val;
45  }
46 
47  return val;
48 }
49 
50 void
51 PolynomialRegressionSurrogate::evaluate(const std::vector<Real> & x, std::vector<Real> & y) const
52 {
53  // Check whether input point has same dimensionality as training data
54  mooseAssert(_power_matrix[0].size() == x.size(),
55  "Input point does not match dimensionality of training data.");
56 
57  y.assign(_coeff.size(), 0.0);
58  for (unsigned int i = 0; i < _power_matrix.size(); ++i)
59  {
60  Real tmp_val(1.0);
61  for (unsigned int j = 0; j < _power_matrix[i].size(); ++j)
62  tmp_val *= MathUtils::pow(x[j], _power_matrix[i][j]);
63  for (unsigned int r = 0; r < _coeff.size(); ++r)
64  y[r] += _coeff[r][i] * tmp_val;
65  }
66 }
PolynomialRegressionSurrogate(const InputParameters &parameters)
const std::vector< double > y
const std::vector< std::vector< Real > > & _coeff
Coefficients of regression model.
registerMooseObject("StochasticToolsApp", PolynomialRegressionSurrogate)
static InputParameters validParams()
const std::vector< double > x
virtual Real evaluate(const std::vector< Real > &x) const override
Evaluate surrogate model given a row of parameters.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void addClassDescription(const std::string &doc_string)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
const std::vector< std::vector< unsigned int > > & _power_matrix
The power matrix for the terms in the polynomial expressions.
T pow(T x, int e)
void ErrorVector unsigned int