Skip to main content

Module optimizer

Module optimizer 

Source
Expand description

Weight-update rules for the trainable networks, ported from tinymind (C++) cpp/adam.hpp and cpp/rmsprop.hpp (C++ TransferFunctionOptimizerPolicy).

A network’s optimizer is a type parameter, as in C++: Sgd (the default, zero-sized, so a network without an adaptive optimizer pays nothing for this), Adam or RmsProp, or for f32 and f64 networks AdamFloat and RmsPropFloat (C++ AdamOptimizerFloat, RmsPropOptimizerFloat; feature std or libm). Pass an adaptive optimizer with its hyperparameters to with_optimizer on NeuralNetwork, MultilayerPerceptron or LstmNetwork. Weight decay and a learning-rate schedule wrap any of them (training).

Every optimizer updates the bias weights as it updates the other weights, and the network’s gradient clipping applies to both. Adam’s step count t advances once per training step, before any weight moves.

The first and second moments live in the connection’s delta-weight slots, as in tinymind (C++), so an adaptive optimizer needs no extra memory per weight.

Structs§

Adam
Adam (C++ AdamOptimizer): per-weight first and second moment estimates with bias correction by 1 - beta^t, beta^t kept as a running product (one multiply per training step). Uses the network’s learning rate; the momentum and acceleration rates do not apply.
AdamFloat
Adam for floating-point networks (C++ AdamOptimizerFloat): the hyperparameters are f64, as in the C++, cast to the network’s type where they are used, and from the first training step bias correction divides by 1 - beta^t, with beta^t a running product in f64. The square root is taken in f64.
RmsProp
RMSprop (C++ RmsPropOptimizer): each weight’s step is scaled by a running root mean square of its gradients. Uses the network’s learning rate only. RmsProp::<Q16_16>::default() and RmsProp::<Q8_8>::default() are tinymind (C++)’s defaults: decay 0.9 and epsilon 1e-8, each rounded to the format and kept above 0 (epsilon is then one LSB).
RmsPropFloat
RMSprop for floating-point networks (C++ RmsPropOptimizerFloat): the hyperparameters are f64, cast to the network’s type where they are used, and the square root is taken in f64.
Sgd
Stochastic gradient descent with momentum and acceleration (the default; C++ NullOptimizerPolicy). The rates are the network’s set_learning_rate, set_momentum_rate and set_acceleration_rate. In fixed point the step learning rate * gradient rounds to nearest (Scalar::mul_round_nearest), so steps below one LSB do not drift one way, and the momentum and acceleration products round toward zero (Scalar::mul_round_toward_zero), so a delta weight no gradient refreshes decays to 0.

Traits§

Optimizer
An optimizer a trainable network can use: Sgd, Adam or RmsProp, and for floating-point networks AdamFloat or RmsPropFloat; any of them wrapped in WeightDecay or Scheduled.