pulsatrix
Loading...
Searching...
No Matches
learnable_scalar.hpp
Go to the documentation of this file.
1
5#pragma once
6
7namespace pulsatrix {
8
24public:
26 explicit LearnableScalar(float initial_value = 0.0f);
27
29 [[nodiscard]] float value() const { return value_; }
30
32 [[nodiscard]] float grad() const { return grad_; }
33
36 void accumulate_grad(float grad);
37
39 void zero_grad();
40
49 void step(float learning_rate);
50
51private:
52 float value_;
53 float grad_ = 0.0f;
54};
55
56} // namespace pulsatrix
A bare learnable scalar (e.g. a GFlowNet loss's log Z), outside the Module/LRP hierarchy entirely.
Definition learnable_scalar.hpp:23
void step(float learning_rate)
Plain SGD update: value_ -= learning_rate * grad_.
float value() const
Current value.
Definition learnable_scalar.hpp:29
LearnableScalar(float initial_value=0.0f)
Constructs a scalar with the given initial value and zero gradient.
void zero_grad()
Resets the accumulated gradient to zero. Does not change value().
float grad() const
Accumulated gradient since the last zero_grad().
Definition learnable_scalar.hpp:32
void accumulate_grad(float grad)
Adds to the accumulated gradient – mirrors Tensor::accumulate()'s across-multiple-contributions conve...
Definition acquisition_functions.hpp:16