pulsatrix
Loading...
Searching...
No Matches
calibration_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
40public:
46 explicit CalibrationLoss(DeviceBackend* backend);
47
63 [[nodiscard]] float forward(const Tensor& probs, const Tensor& target_class);
64
71 [[nodiscard]] Tensor backward() const;
72
73private:
74 DeviceBackend* backend_;
75 Tensor last_probs_;
76 std::vector<int64_t> last_target_indices_;
77 Tensor last_one_hot_ = Tensor(Shape({0}), backend_); // (N, num_classes), on the probs' device
78 bool has_forwarded_ = false;
79};
80
81} // namespace pulsatrix
BS = mean_n( Σ_k (p[n,k] − y[n,k])² ), y one-hot at target_class[n] – Brier's original multi-class pr...
Definition calibration_loss.hpp:39
Tensor backward() const
Gradient w.r.t. probs: 2(p[n,k] − y[n,k]) / N.
CalibrationLoss(DeviceBackend *backend)
Constructs a calibration loss.
float forward(const Tensor &probs, const Tensor &target_class)
Computes the Brier score and caches what backward() needs.
Vendor-agnostic compute/memory backend. CPUBackend, CUDABackend (Phase 1.5), and HIPBackend (Phase 1....
Definition device_backend.hpp:219
An N-dimensional shape. A plain aggregate of dimensions with no invariant beyond "non-negative dimens...
Definition shape.hpp:24
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).