A bare learnable scalar (e.g. a GFlowNet loss's log Z), outside the Module/LRP hierarchy entirely.
More...
#include <learnable_scalar.hpp>
|
| | LearnableScalar (float initial_value=0.0f) |
| | Constructs a scalar with the given initial value and zero gradient.
|
| |
| float | value () const |
| | Current value.
|
| |
| float | grad () const |
| | Accumulated gradient since the last zero_grad().
|
| |
| void | accumulate_grad (float grad) |
| | Adds to the accumulated gradient – mirrors Tensor::accumulate()'s across-multiple-contributions convention.
|
| |
| void | zero_grad () |
| | Resets the accumulated gradient to zero. Does not change value().
|
| |
| void | step (float learning_rate) |
| | Plain SGD update: value_ -= learning_rate * grad_.
|
| |
A bare learnable scalar (e.g. a GFlowNet loss's log Z), outside the Module/LRP hierarchy entirely.
- Note
- Deliberately not a Module:
AdamOptimizer/SGDOptimizer only operate over Module::parameters(), and forcing a training-only scalar into the Module contract would also force a propagate_relevance definition for something with no forward pass to explain – the same reasoning that keeps MSELoss outside the Module hierarchy (see mission_shared_gflownet_machinery.md's Recon). The GFlowNet losses this class supports compute d(loss)/d(log Z) analytically themselves; no autograd machinery is needed here at all.
-
Not a Tensor either – a Tensor's whole reason to exist (device placement, batched storage, DeviceBackend dispatch) is irrelevant to one scalar that never participates in a tensor op.
◆ LearnableScalar()
| pulsatrix::LearnableScalar::LearnableScalar |
( |
float |
initial_value = 0.0f | ) |
|
|
explicit |
Constructs a scalar with the given initial value and zero gradient.
◆ accumulate_grad()
| void pulsatrix::LearnableScalar::accumulate_grad |
( |
float |
grad | ) |
|
Adds to the accumulated gradient – mirrors Tensor::accumulate()'s across-multiple-contributions convention.
◆ grad()
| float pulsatrix::LearnableScalar::grad |
( |
| ) |
const |
|
inline |
◆ step()
| void pulsatrix::LearnableScalar::step |
( |
float |
learning_rate | ) |
|
Plain SGD update: value_ -= learning_rate * grad_.
- Parameters
-
| learning_rate | Step size. Unvalidated – same convention as SGDOptimizer's own constructor, which does not validate its learning rate either. |
- Note
- Does not reset grad() – mirrors AdamOptimizer::step()'s own convention (zero_grad() is a separate, explicit call).
◆ value()
| float pulsatrix::LearnableScalar::value |
( |
| ) |
const |
|
inline |
◆ zero_grad()
| void pulsatrix::LearnableScalar::zero_grad |
( |
| ) |
|
Resets the accumulated gradient to zero. Does not change value().
The documentation for this class was generated from the following file: