# SPSA

Home * Programming * Algorithms * SPSA

SPSA, (Simultaneous Perturbation Stochastic Approximation)
a stochastic approximation algorithm devised in the late 80s [1] and 90s by James C. Spall [2]. It is an extension of the Finite Difference Stochastic Approximation (FDSA) algorithm aka Kiefer-Wolfowitz algorithm introduced in 1952 by Jack Kiefer and Jacob Wolfowitz [3], on the other hand motivated by the publication of the Robbins-Monro algorithm in 1951 [4].

The SPSA algorithm is suited for high-dimensional optimization problems giving an objective function of a p-dimensional vector of adjustable weights, Theta or Θ, using a gradient approximation that requires only N+1 or 2N objective function measurements over all N iterations regardless of the dimension of the optimization problem - opposed to FDSA, which needs p + 1 objective function measurements or simulations per step. At each iteration, a simultaneous perturbation vector with mutually independent zero-mean random variables is generated, a good choice for each delta is the Rademacher distribution with probability ½ of being either +1 or -1. Two feature vectors Θ+ and Θ- are calculated by adding and subtracting the delta vector scaled by gain sequence ck to/from the current feature vector Θ, to compare their objective function measurements. Dependent on the outcome and scaled by gain sequences ak and ck, the current feature vector is approximated accordantly. The gain sequences decrease with increasing iterations, converging to 0. The theory pertains to both local optimization and global optimization in the face of multiple local optima [5].

# Automated Tuning

```α = 0.602; γ = 0.101;
for (k=0; k < N; k++) {
ak = a / (k + 1 + A)^α;
ck = c / (k + 1)^γ;
for each p
Δp = 2 * round ( rand() / (RAND_MAX + 1.0) ) - 1.0;
Θ+ = Θ + ck*Δ;
Θ- = Θ - ck*Δ;
Θ +=  ak * match(Θ+, Θ-) / (ck*Δ);
}
```

In computer chess or games, where the objective function reflects the playing strength to maximize, SPSA can be used in automated tuning of evaluation parameters as well as search parameters. A prominent SPSA instance is devised from Stockfish's tuning method as introduced by Joona Kiiski in 2011 [6], where the objective function is measured once per iteration by playing a pair of games with Θ+ versus Θ-, the function "match" returning a ±2 range, see pseudo code. The selection of the coefficients A, a, c, α and γ determine the initial values and time decay of the gain sequences ak and ck, is critical to the performance of SPSA. Spall recommends using α = 0.602 and γ = 0.101, which are the lowest possible values which theoretically guarantees convergence, further see the practical suggestions in Spall's 1998 SPSA implementation paper [7].

# RSPSA

Already at the Advances in Computer Games 11 conference at Academia Sinica, Taipei, Taiwan in 2005, Levente Kocsis, Csaba Szepesvári, and Mark Winands introduced SPSA for the game programming community and discussed several methods that can be used to enhance its performance, including the use of common random numbers and antithetic variates, a combination of SPSA with RPROP (resilient backpropagation), and the reuse of samples of previous performance evaluations. RPROP, though it was originally worked out for the training of neural networks, is applicable to any optimization task where the gradient can be computed or approximated [8]. The described RSPSA (Resilient SPSA) was successfully applied in parameter tuning in the domains of Poker and Lines of Action [9].

# Forum Posts

## 2010 ...

Re: Stockfish's tuning method by Rémi Coulom, CCC, October 07, 2011

## 2015 ...

Re: A plea to someone by Jon Dart, CCC, April 08, 2015