Line data Source code
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 : 10 : #include "PolynomialRegressionSurrogate.h" 11 : 12 : registerMooseObject("StochasticToolsApp", PolynomialRegressionSurrogate); 13 : 14 : InputParameters 15 768 : PolynomialRegressionSurrogate::validParams() 16 : { 17 768 : InputParameters params = SurrogateModel::validParams(); 18 768 : params.addClassDescription("Evaluates polynomial regression model with coefficients computed " 19 : "from PolynomialRegressionTrainer."); 20 768 : return params; 21 0 : } 22 : 23 382 : PolynomialRegressionSurrogate::PolynomialRegressionSurrogate(const InputParameters & parameters) 24 : : SurrogateModel(parameters), 25 382 : _coeff(getModelData<std::vector<std::vector<Real>>>("_coeff")), 26 764 : _power_matrix(getModelData<std::vector<std::vector<unsigned int>>>("_power_matrix")), 27 1146 : _max_degree(getModelData<unsigned int>("_max_degree")) 28 : { 29 382 : } 30 : 31 : Real 32 378214 : 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 6060578 : for (unsigned int i = 0; i < _power_matrix.size(); ++i) 40 : { 41 : Real tmp_val(1.0); 42 28148292 : for (unsigned int j = 0; j < _power_matrix[i].size(); ++j) 43 22465928 : tmp_val *= MathUtils::pow(x[j], _power_matrix[i][j]); 44 5682364 : val += _coeff[0][i] * tmp_val; 45 : } 46 : 47 378214 : return val; 48 : } 49 : 50 : void 51 528 : 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 528 : y.assign(_coeff.size(), 0.0); 58 2442 : for (unsigned int i = 0; i < _power_matrix.size(); ++i) 59 : { 60 : Real tmp_val(1.0); 61 5742 : for (unsigned int j = 0; j < _power_matrix[i].size(); ++j) 62 3828 : tmp_val *= MathUtils::pow(x[j], _power_matrix[i][j]); 63 18942 : for (unsigned int r = 0; r < _coeff.size(); ++r) 64 17028 : y[r] += _coeff[r][i] * tmp_val; 65 : } 66 528 : }