pub fn adam(learning_rate: f64) -> Chain<ScaleByAdam, Scale>Expand description
Adam with a constant learning rate (optax.adam); set the other
hyperparameters on the result’s first part.
§Examples
use ruxla_core::{Array, Native};
use ruxla_nn::optim::{GradientTransformation, adam, apply_updates};
let params = (Array::<Native, f32>::from_vec(vec![1.0, 2.0], [2]),);
let opt = adam(0.1);
let state = opt.init_tree::<Native, f32, _>(¶ms);
let grads = (Array::<Native, f32>::from_vec(vec![0.5, -0.5], [2]),);
let (updates, _state) = opt.update_tree(&grads, state);
let params = apply_updates::<Native, f32, _>(¶ms, &updates);
// The first step of Adam moves each parameter by about the learning
// rate; the values are those of Optax.
assert_eq!(params.0.to_vec(), [0.9000007, 2.0999994]);