LCOV - code coverage report
Current view: top level - src/surrogates - PolynomialRegressionSurrogate.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: #32971 (54bef8) with base c6cf66 Lines: 23 24 95.8 %
Date: 2026-05-29 20:40:35 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         346 : PolynomialRegressionSurrogate::validParams()
      16             : {
      17         346 :   InputParameters params = SurrogateModel::validParams();
      18         346 :   params.addClassDescription("Evaluates polynomial regression model with coefficients computed "
      19             :                              "from PolynomialRegressionTrainer.");
      20         346 :   return params;
      21           0 : }
      22             : 
      23         172 : PolynomialRegressionSurrogate::PolynomialRegressionSurrogate(const InputParameters & parameters)
      24             :   : SurrogateModel(parameters),
      25         172 :     _coeff(getModelData<std::vector<std::vector<Real>>>("_coeff")),
      26         344 :     _power_matrix(getModelData<std::vector<std::vector<unsigned int>>>("_power_matrix")),
      27         516 :     _max_degree(getModelData<unsigned int>("_max_degree"))
      28             : {
      29         172 : }
      30             : 
      31             : Real
      32      172064 : 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     2755698 :   for (unsigned int i = 0; i < _power_matrix.size(); ++i)
      40             :   {
      41             :     Real tmp_val(1.0);
      42    12798402 :     for (unsigned int j = 0; j < _power_matrix[i].size(); ++j)
      43    10214768 :       tmp_val *= MathUtils::pow(x[j], _power_matrix[i][j]);
      44     2583634 :     val += _coeff[0][i] * tmp_val;
      45             :   }
      46             : 
      47      172064 :   return val;
      48             : }
      49             : 
      50             : void
      51         240 : 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         240 :   y.assign(_coeff.size(), 0.0);
      58        1110 :   for (unsigned int i = 0; i < _power_matrix.size(); ++i)
      59             :   {
      60             :     Real tmp_val(1.0);
      61        2610 :     for (unsigned int j = 0; j < _power_matrix[i].size(); ++j)
      62        1740 :       tmp_val *= MathUtils::pow(x[j], _power_matrix[i][j]);
      63        8610 :     for (unsigned int r = 0; r < _coeff.size(); ++r)
      64        7740 :       y[r] += _coeff[r][i] * tmp_val;
      65             :   }
      66         240 : }

Generated by: LCOV version 1.14