Adagrad optimiser — accumulates squared gradients without forgetting.
Maintains a running sum of per parameter and scales the learning rate by its inverse square root. The accumulator grows monotonically so the effective learning rate decays to zero in the limit — well suited to sparse features (NLP, embeddings) but typically too aggressive for dense deep-network weights.
Math
where is the slot's own step count (1 on its first update) and
is lr_decay.
References
Duchi, Hazan & Singer, "Adaptive Subgradient Methods for Online Learning and Stochastic Optimization" (JMLR 12, 2011).
See Also
Adadelta, RMSprop — both add a forgetting factor
to address Adagrad's monotonic learning-rate decay.
Parameters
paramsvector of TensorImpllrfloat, default 1e-2lr_ decayfloat, default 0.0weight_ decayfloat, default 0.0initial_ accumulator_ valuefloat, default 0.0sum_sq_grad_. A non-zero value avoids dividing by a near-zero accumulator on the very first step.epsfloat, default 1e-10Attributes
sum_ sq_ grad_vector of StorageNotes
Because the accumulator never decays, the effective per-parameter learning rate is non-increasing — once a coordinate has seen large gradients its step shrinks for the rest of training. This is precisely what makes Adagrad strong on sparse problems and weak on long dense-network runs.
Constructors
1Construct the optimiser and resize per-slot state vectors.
Parameters
paramsvector of TensorImpllrfloat, default 1e-2lr_ decayfloat, default 0.0weight_ decayfloat, default 0.0initial_ accumulator_ valuefloat, default 0.0sum_sq_grad_.epsfloat, default 1e-10Notes
The order is the reference framework's, not that of the Python
wrapper (which keeps eps before initial_accumulator_value
for its released signature) — the wrapper passes every argument by
keyword.
Static methods
1check_hyperparams
void check_hyperparams(double lr, double lr_decay, double weight_decay, double initial_accumulator_value, double eps)Check Adagrad's hyper-parameters — the reference framework's constructor checks, run by the constructor and set_hyperparams.
Raises
InvalidArgumentVirtual methods
2Methods
5Allocate the squared-gradient accumulator for parameter i.
Parameters
iintNotes
When initial_accumulator_value_ != 0 the buffer is filled
with that scalar rather than zeros.
set_hyperparams
void set_hyperparams(double lr, double lr_decay, double weight_decay, double initial_accumulator_value, double eps)Replace the hyper-parameters between steps; nothing is applied when check_hyperparams rejects them.
Notes
initial_accumulator_value is checked but not applied: it seeds
the accumulator once, as the reference framework reads it once at
construction, so an edit has no effect there either.
Return the versioned state-dict identifier.
Returns
str"adagrad_v1".
Apply one Adagrad update to parameter i.
Parameters
iintgStoragep on this step.Notes
Accumulates into sum_sq_grad_[i] then applies
with the
decayed step size .