LCOV - code coverage report
Current view: top level - src/surrogates - PolynomialRegressionSurrogate.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: f45d79 Lines: 23 24 95.8 %
Date: 2025-07-25 05:00:46 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          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         716 : PolynomialRegressionSurrogate::validParams()
      16             : {
      17         716 :   InputParameters params = SurrogateModel::validParams();
      18         716 :   params.addClassDescription("Evaluates polynomial regression model with coefficients computed "
      19             :                              "from PolynomialRegressionTrainer.");
      20         716 :   return params;
      21           0 : }
      22             : 
      23         356 : PolynomialRegressionSurrogate::PolynomialRegressionSurrogate(const InputParameters & parameters)
      24             :   : SurrogateModel(parameters),
      25         356 :     _coeff(getModelData<std::vector<std::vector<Real>>>("_coeff")),
      26         712 :     _power_matrix(getModelData<std::vector<std::vector<unsigned int>>>("_power_matrix")),
      27        1068 :     _max_degree(getModelData<unsigned int>("_max_degree"))
      28             : {
      29         356 : }
      30             : 
      31             : Real
      32      343832 : 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     5509624 :   for (unsigned int i = 0; i < _power_matrix.size(); ++i)
      40             :   {
      41             :     Real tmp_val(1.0);
      42    25589376 :     for (unsigned int j = 0; j < _power_matrix[i].size(); ++j)
      43    20423584 :       tmp_val *= MathUtils::pow(x[j], _power_matrix[i][j]);
      44     5165792 :     val += _coeff[0][i] * tmp_val;
      45             :   }
      46             : 
      47      343832 :   return val;
      48             : }
      49             : 
      50             : void
      51         480 : 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         480 :   y.assign(_coeff.size(), 0.0);
      58        2220 :   for (unsigned int i = 0; i < _power_matrix.size(); ++i)
      59             :   {
      60             :     Real tmp_val(1.0);
      61        5220 :     for (unsigned int j = 0; j < _power_matrix[i].size(); ++j)
      62        3480 :       tmp_val *= MathUtils::pow(x[j], _power_matrix[i][j]);
      63       17220 :     for (unsigned int r = 0; r < _coeff.size(); ++r)
      64       15480 :       y[r] += _coeff[r][i] * tmp_val;
      65             :   }
      66         480 : }

Generated by: LCOV version 1.14