10#ifdef MOOSE_LIBTORCH_ENABLED
15 : _clip_parameter(clip_parameter), _entropy_coeff(entropy_coeff)
25 policy_network.
evaluate(observations,
false);
27 const auto current_log_probability =
32 const auto ratio = (current_log_probability - previous_log_probability).exp();
41 output.
entropy = entropy.mean();
48 if (!tensor.defined())
51 if (tensor.dim() == 1)
52 return tensor.unsqueeze(1);
54 if (tensor.size(-1) == 1)
57 return tensor.sum(-1,
true);
static torch::Tensor reduceActionDimension(const torch::Tensor &tensor)
Collapse multi-action log-probabilities or entropies into one column tensor.
const Real _entropy_coeff
Weight applied to the entropy bonus inside the actor loss.
const Real _clip_parameter
PPO clipping width used in the actor surrogate objective.
LibtorchRLPPOLoss(Real clip_parameter, Real entropy_coeff)
Build the PPO loss helper.
LibtorchRLPPOLossOutput compute(Moose::LibtorchActorNeuralNet &policy_network, Moose::LibtorchArtificialNeuralNet &value_network, const LibtorchRLMiniBatch &batch) const
Compute actor, critic, and entropy terms for one mini-batch.
Feed-forward actor network coupled to a Gaussian or Beta action distribution.
torch::Tensor logProbability(const torch::Tensor &other)
Evaluate the log-probability of an action under the current actor state.
virtual torch::Tensor evaluate(torch::Tensor &input, bool sampled, c10::optional< at::Generator > generator=c10::nullopt)
Evaluate the actor and either sample from it or use its deterministic action.
torch::Tensor entropy()
Compute the entropy of the current action distribution.
virtual torch::Tensor forward(const torch::Tensor &x) override
Tensor data for one PPO mini-batch.
torch::Tensor actions
Action rows that match the sampled observations.
torch::Tensor value_targets
Critic targets aligned with the sampled observations.
torch::Tensor old_log_probabilities
Behavior-policy log probabilities for the sampled actions.
torch::Tensor advantages
Advantage estimates aligned with the sampled observations.
torch::Tensor observations
Flattened observation rows for the mini-batch.
Actor, critic, and entropy terms produced by one PPO loss evaluation.
torch::Tensor actor_loss
Clipped actor loss for the current mini-batch.
torch::Tensor critic_loss
Critic regression loss for the current mini-batch.
torch::Tensor entropy
Mean action-distribution entropy for the current mini-batch.