pulsatrix
Loading...
Searching...
No Matches
pulsatrix::LearnableScalar Class Reference

A bare learnable scalar (e.g. a GFlowNet loss's log Z), outside the Module/LRP hierarchy entirely. More...

#include <learnable_scalar.hpp>

Public Member Functions

 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_.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ LearnableScalar()

pulsatrix::LearnableScalar::LearnableScalar ( float  initial_value = 0.0f)
explicit

Constructs a scalar with the given initial value and zero gradient.

Member Function Documentation

◆ 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

Accumulated gradient since the last zero_grad().

◆ step()

void pulsatrix::LearnableScalar::step ( float  learning_rate)

Plain SGD update: value_ -= learning_rate * grad_.

Parameters
learning_rateStep 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

Current value.

◆ 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: