https://mooseframework.inl.gov
ScaledAbsDifferenceDRLRewardFunction.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 
19  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  params.addRequiredParam<FunctionName>("design_function", "The desired value to reach.");
24  params.addRequiredParam<PostprocessorName>(
25  "observed_value", "The name of the Postprocessor that contains the observed value.");
26 
27  params.addParam<Real>("c1", 10, "1st coefficient in the reward function.");
28  params.addParam<Real>("c2", 1, "2nd coefficient in the reward function.");
29 
30  return params;
31 }
32 
34  const InputParameters & parameters)
35  : Function(parameters),
36  FunctionInterface(this),
37  _design_function(getFunction("design_function")),
38  _observed_value(getPostprocessorValueByName(getParam<PostprocessorName>("observed_value"))),
39  _c1(getParam<Real>("c1")),
40  _c2(getParam<Real>("c2"))
41 {
42 }
43 
44 Real
45 ScaledAbsDifferenceDRLRewardFunction::value(Real t, const Point & p) const
46 {
47  Real design_value = _design_function.value(t, p);
48  return -_c1 * std::abs(design_value - _observed_value) + _c2;
49 }
50 
51 ADReal
53 {
54  ADReal design_value = _design_function.value(t, p);
55  return -_c1 * std::abs(design_value - _observed_value) + _c2;
56 }
ScaledAbsDifferenceDRLRewardFunction(const InputParameters &parameters)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
DualNumber< Real, DNDerivativeType, true > ADReal
void addRequiredParam(const std::string &name, const std::string &doc_string)
const PostprocessorValue & _observed_value
Postprocessor containing the observed value.
A simple reward function which uses c1*|x-x_target|+c2.
const Real & _c1
Coefficients for the reward function.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
registerMooseObject("StochasticToolsApp", ScaledAbsDifferenceDRLRewardFunction)
void addClassDescription(const std::string &doc_string)
virtual Real value(Real t, const Point &p) const override
virtual Real value(Real t, const Point &p) const
const Function & _design_function
Value we would like to reach (can be time and space dependent)
static InputParameters validParams()