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.

See minimize() for a description of fun, x0, and args.

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}{(k+1)^{\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}{(k+1)^{\gamma}}\) for scaling parameters \(c, \gamma>0\), and \(\Delta_k\) is a random perturbation vector with components independently drawn from \(\{-1, +1\}\).

Parameters:
maxiterint

Maximum number of iterations to perform. Each iteration requires 2 function evaluations.

afloat

Scaling parameter for update rule.

cfloat

Scaling parameter for gradient estimation.

alphafloat

Scaling exponent for update rule.

gammafloat

Scaling exponent for gradient estimation.

seedint, optional

The seed for the pseudo-random number generator used to draw the perturbation vectors \(\Delta_k\). The default is 3.

Returns:
results

An OptimizeResults object.