SPSA#
- spsa(fun, x0, args, maxiter=50, a=2.0, c=0.1, alpha=0.702, gamma=0.201, seed=3)[source]#
Minimize a scalar function of one or more variables using the Simultaneous Perturbation Stochastic Approximation algorithm.
This algorithm aims at finding the optimal control \(x^*\) minimizing a given loss fuction \(f\):
\[x^* = \text{argmin}_{x} f(x)\]This is done by an iterative process starting from an initial guess \(x_0\):
\[x_{k+1} = x_k - a_kg_k(x_k)\]where \(a_k=\dfrac{a}{n^{\alpha}}\) for scaling parameters \(a, \alpha>0\).
For each step \(x_k\) the gradient is approximated by
\[(g_k(x_k))_i = \frac{f(x_k+c_k\Delta_k)-f(x_k-c_k\Delta_k)}{2c_k(\Delta_k)_i}\]where \(c_k=\dfrac{c}{n^{\gamma}}\) for scaling parameters \(c, \gamma>0\), and \(\Delta_k\) is a random perturbation vector.
- Parameters:
- maxiterint
Maximum number of iterations to perform. Each iteration requires 2 function evaluations.
- afloat
Scaling parameter for update rule.
- alphafloat
Scaling exponent for update rule.
- cfloat
Scaling parameter for gradient estimation.
- gammafloat
Scaling exponent for gradient estimation.
- Returns:
- results
An OptimizeResults object.