Skip to main content

Module sgd_optimizer

Module sgd_optimizer 

Source
Expand description

SGD Optimizer variants for tensor parameter optimization.

Provides stochastic gradient descent with optional momentum, Nesterov acceleration, weight decay, and dampening. Designed for training loops inside the TensorLogic subsystem.

§Supported variants

VariantUpdate rule
SGDp -= lr * (g + wd * p)
SGDMomentumv = m*v + (1-d)*g; p -= lr*(v + wd*p)
SGDNesterovv = m*v + g; p -= lr*(g + m*v + wd*p)

§Example

use ipfrs_tensorlogic::sgd_optimizer::{SGDConfig, SGDOptimizer, OptimizerType};
use std::collections::HashMap;

let config = SGDConfig::default();
let mut opt = SGDOptimizer::new(config);
opt.register_parameter("w", vec![1.0, 2.0, 3.0]);

let mut grads = HashMap::new();
grads.insert("w".to_string(), vec![0.1, 0.2, 0.3]);
opt.step(&grads).expect("example: should succeed in docs");

let w = opt.get_parameter("w").expect("example: should succeed in docs");
assert!(w[0] < 1.0); // parameter decreased

Structs§

ParameterState
Per-parameter mutable state tracked by the optimizer.
SGDConfig
Configuration for an SGDOptimizer.
SGDOptimizer
Stochastic gradient descent optimizer with momentum, Nesterov, and weight decay support.
SGDOptimizerStats
Summary statistics returned by SGDOptimizer::stats.

Enums§

OptimizerType
Which SGD variant to use.