https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
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),
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
44Real
46{
47 Real design_value = _design_function.value(t, p);
48 return -_c1 * std::abs(design_value - _observed_value) + _c2;
49}
50
53{
54 using std::abs;
55 ADReal design_value = _design_function.value(t, p);
56 return -_c1 * abs(design_value - _observed_value) + _c2;
57}
DualNumber< Real, DNDerivativeType, true > ADReal
const Real p
registerMooseObject("StochasticToolsApp", ScaledAbsDifferenceDRLRewardFunction)
static InputParameters validParams()
virtual Real value(Real t, const Point &p) const
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
A simple reward function which uses c1*|x-x_target|+c2.
const Function & _design_function
Value we would like to reach (can be time and space dependent)
const PostprocessorValue & _observed_value
Postprocessor containing the observed value.
virtual Real value(Real t, const Point &p) const override
const Real & _c1
Coefficients for the reward function.
ScaledAbsDifferenceDRLRewardFunction(const InputParameters &parameters)