Overview
stochy is a collection of stochastic approximation algorithms:
RSPSA(Resilient Simultaneous Perturbation Stochastic Approximation)SPSA(Simultaneous Perturbation Stochastic Approximation)
You can use stochy to:
- Minimize functions with multiple parameters, without needing a gradient function
- Optimize parameters in game-playing programs using relative difference functions
stochy is compatible with both the stepwise solver API and
the argmin solver API (enable via the argmin feature flag).
Usage
Example Cargo.toml:
[]
= "0.0.2"
# if using argmin, replace above with...
# stochy = { version = "0.0.2", features = ["argmin"] }
Example
use ;
use ;
let f = ;
let hyperparams = default;
let spsa = from_fn.expect;
let = fixed_iters
.on_step
.solve
.expect;
assert_approx_eq!;
println!;
Example (argmin)
use assert_approx_eq;
;
#
let hyperparams = default;
let algo = new;
let exec = new;
let initial_param = vec!;
let result = exec
.configure
.run
.unwrap;
let best_param = result.state.best_param.unwrap;
assert_approx_eq!;
Comparison
| Gradient Descent (for comparison) | RSPSA | SPSA |
|---|---|---|
| Requires gradient function | No gradient function required | No gradient function required |
| Requires gradient function | Accepts relative difference function | Accepts relative difference function |
| One gradient eval per iteration | Two function evals per iteration | Two function evals per iteration |
| Single learning-rate hyperparameter | Very sensitive to hyperparameters | Less sensitive to hyperparameters than SPSA |
| Continuous convergence progression | Convergence saturation | Continuous convergence progression |