Overview
Stochy is a collection of stochastic approximation algorithms - methods for optimizing systems with multiple unknown parameters.
The algos can be used with stepwise (built-in, the default) or with argmin (using feature-flag argmin).
Neither algo requires a gradient function, only the objective function to be minimised. Alternatively a proxy to relative differences of objective function evaluations can be specified. See Relative difference functions
RSPSA algorithm
Resiliant Simultaneous Perturbation Stochastic Approximation.
[RspsaSolver]
SPSA algorithm
Simultaneous Perturbation Stochastic Approximation.
[SpsaSolver]
Crate features
By default no features are enabled.
Features:
argmin: enable integration with argmin.
Example Cargo.toml
[]
= { = "0.0.1", = ["argmin"] }
Example
The [stepwise::Driver] has functional style iteration control methods,
along with a solve call which returns the algo (in a solved state)
along with final iteration step.
The on_step() logging and progress bar are optional, and can be omitted.
# use Duration;
use ;
use ;
let f = ;
let hyperparams = default;
let algo = from_fn.expect;
let driver = fixed_iters
.on_step
.show_progress_bar_after;
let = driver.solve.expect;
assert_approx_eq!;
Example (Argmin)
In the below, use statements have been replaced by full qualification of paths, to make clear what
structs or functions come from which crates.
;
#
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 |
|---|---|---|
| Gradient function required | No gradient function required | No gradient function required |
| Gradient function required | 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 |
Relative Differences
Rather than specifying an objective function to be minimised (cost function), a relative difference function can be specified.
df(x1, x2) ~ f(x2) - f(x1)
which permits use in cases where an abolute value of objective function is unavailable. Typically a game playing program would seek to minimise -df (and hence maximize df) where x₁ and x₂ represent game playing parameters, and the difference function df represents the outcome of a single game or a series of games.
/ +1 x₂ win vs x₁ loss
df(x₁, x₂) = 0 drawn game
\ -1 x₂ loss vs x₁ win