LCOV - code coverage report
Current view: top level - src/functions - ScaledAbsDifferenceDRLRewardFunction.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: f45d79 Lines: 18 22 81.8 %
Date: 2025-07-25 05:00:46 Functions: 3 4 75.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 "ScaledAbsDifferenceDRLRewardFunction.h"
      11             : 
      12             : registerMooseObject("StochasticToolsApp", ScaledAbsDifferenceDRLRewardFunction);
      13             : 
      14             : InputParameters
      15          57 : ScaledAbsDifferenceDRLRewardFunction::validParams()
      16             : {
      17          57 :   InputParameters params = Function::validParams();
      18             : 
      19          57 :   params.addClassDescription(
      20             :       "Evaluates a scaled absolute difference reward function for a process "
      21             :       "which is controlled by a Deep Reinforcement Learning based surrogate.");
      22             : 
      23         114 :   params.addRequiredParam<FunctionName>("design_function", "The desired value to reach.");
      24         114 :   params.addRequiredParam<PostprocessorName>(
      25             :       "observed_value", "The name of the Postprocessor that contains the observed value.");
      26             : 
      27         114 :   params.addParam<Real>("c1", 10, "1st coefficient in the reward function.");
      28         114 :   params.addParam<Real>("c2", 1, "2nd coefficient in the reward function.");
      29             : 
      30          57 :   return params;
      31           0 : }
      32             : 
      33          33 : ScaledAbsDifferenceDRLRewardFunction::ScaledAbsDifferenceDRLRewardFunction(
      34          33 :     const InputParameters & parameters)
      35             :   : Function(parameters),
      36             :     FunctionInterface(this),
      37          33 :     _design_function(getFunction("design_function")),
      38          66 :     _observed_value(getPostprocessorValueByName(getParam<PostprocessorName>("observed_value"))),
      39          66 :     _c1(getParam<Real>("c1")),
      40          99 :     _c2(getParam<Real>("c2"))
      41             : {
      42          33 : }
      43             : 
      44             : Real
      45         856 : ScaledAbsDifferenceDRLRewardFunction::value(Real t, const Point & p) const
      46             : {
      47         856 :   Real design_value = _design_function.value(t, p);
      48         856 :   return -_c1 * std::abs(design_value - _observed_value) + _c2;
      49             : }
      50             : 
      51             : ADReal
      52           0 : ScaledAbsDifferenceDRLRewardFunction::value(const ADReal & t, const ADPoint & p) const
      53             : {
      54           0 :   ADReal design_value = _design_function.value(t, p);
      55           0 :   return -_c1 * std::abs(design_value - _observed_value) + _c2;
      56             : }

Generated by: LCOV version 1.14