pulsatrix
Loading...
Searching...
No Matches
policy_gradient_loss.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <cstdint>
8#include <vector>
9
11#include "pulsatrix/tensor.hpp"
12
13namespace pulsatrix {
14
53public:
59
81 [[nodiscard]] float forward(const Tensor& logits, const Tensor& actions, const Tensor& returns);
82
100 [[nodiscard]] Tensor backward() const;
101
102private:
103 DeviceBackend* backend_;
107 Tensor last_probs_;
108 Tensor last_returns_;
112 Tensor last_action_indices_;
113 bool has_forwarded_ = false;
114};
115
116} // namespace pulsatrix
Vendor-agnostic compute/memory backend. CPUBackend, CUDABackend (Phase 1.5), and HIPBackend (Phase 1....
Definition device_backend.hpp:219
loss = mean_b( -log pi(a_b | s_b) * G_b ), where a_b is the action actually taken on step b of a roll...
Definition policy_gradient_loss.hpp:52
Tensor backward() const
Gradient w.r.t. logits: returns[b,0] * (p[b,k] - 1{k == a_b}) / N, the softmax/cross-entropy gradient...
float forward(const Tensor &logits, const Tensor &actions, const Tensor &returns)
Computes the return-weighted negative log-likelihood and caches what backward() needs.
PolicyGradientLoss(DeviceBackend *backend)
Constructs a policy-gradient loss.
N-dimensional tensor. Owns its data buffer exclusively; a DeviceBackend* is injected (not owned) – th...
Definition tensor.hpp:29
Abstract interface isolating vendor-specific memory/compute operations from Tensor/ComputationGraph.
Definition acquisition_functions.hpp:16
N-dimensional tensor – owns a buffer via DeviceBackend*, RAII (Rule of Five).