https://mooseframework.inl.gov
Loading...
Searching...
No Matches
DRLRewardReporter.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
10#ifdef MOOSE_LIBTORCH_ENABLED
11
12#include "DRLRewardReporter.h"
13
15
18{
21
22 params.addClassDescription("Reporter containing the reward values of a DRL controller trainer.");
23 params.addRequiredParam<UserObjectName>(
24 "drl_trainer_name", "The name of the DRL controller trainer which computes the rewards.");
25
26 return params;
27}
28
30 : GeneralReporter(parameters),
32 _average_reward(declareValueByName<Real>("average_reward", REPORTER_MODE_ROOT)),
33 _std_reward(declareValueByName<Real>("std_reward", REPORTER_MODE_ROOT)),
34 _sample_average_reward(
35 declareValueByName<std::vector<Real>>("sample_average_reward", REPORTER_MODE_ROOT)),
36 _sample_std_reward(
37 declareValueByName<std::vector<Real>>("sample_std_reward", REPORTER_MODE_ROOT)),
38 _trainer(getSurrogateTrainer<LibtorchDRLControlTrainer>("drl_trainer_name"))
39{
40}
41
42void
50
51#endif
registerMooseObject("StochasticToolsApp", DRLRewardReporter)
const ReporterMode REPORTER_MODE_ROOT
Reporter which saves the reward values from a Deep Reinforcement Learning controller trainer.
DRLRewardReporter(const InputParameters &parameters)
Construct using input parameters.
std::vector< Real > & _sample_average_reward
The per-sample average reward values which will be saved.
static InputParameters validParams()
Return the input parameters supported by this reporter.
LibtorchDRLControlTrainer & _trainer
The DRL trainer which computes the reward values.
std::vector< Real > & _sample_std_reward
The per-sample reward standard deviations which will be saved.
Real & _std_reward
The standard deviation of the reward values which will be saved.
virtual void execute() override
Update the reported reward statistics.
Real & _average_reward
The reward values which will be saved.
static InputParameters validParams()
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
Fixed-horizon actor-critic trainer that collects trajectories from MOOSE reporters and runs a PPO upd...
std::vector< Real > sampleAverageEpsiodeRewards()
Return per-sample mean episodic rewards from the latest update window.
Real averageEpisodeReward()
Return the current average episodic reward.
std::vector< Real > sampleStdEpsiodeRewards()
Return per-sample episodic reward standard deviations from the latest update window.
Real stdEpisodeReward()
Return the current episodic reward standard deviation.
Interface for objects that need to use samplers.
static InputParameters validParams()