Optimization of a Neural Network

William S. Harlan

Feb 1999

Introduction

Many discussions of neural networks unnecessarily introduce a large vocabulary of specialized terms. In fact, neural networks are a simple system of recursive equations that can be optimized by conventional means. Any good book on optimization provides all the necessary tools [1]. We need only unambiguously write down the equations we are using, identify the objective function, and calculate a few derivatives.

The Recursive Equations

Neural-network equations map vectors of known data d^{m} to corresponding known vectors of parameters p^{m}, indexed by m. The vector of parameters might be actual physical properties or statistical probabilities. Data can be physical measurements or numbers that index possible events. The equations contain unknown coefficients, or weights, that the user adjusts until known parameters are predicted accurately. Then it is hoped that unknown parameters can be estimated from new measurements of data.

Let’s look at how simple these equations are. Intermediate vectors x^{m,n} are expressed recursively as a function of other vectors x^{m,n−1}, usually with a different dimensionality. The first vector x^{m,0} corresponds to data d^{m}, and the final vector x^{m,N} corresponds to the parameters p^{m} to be estimated. First, a pre-established non-linear transform f^{n} is applied to each element of a vector. Then linear transforms W̃^{n} calculate each sample of the output vector as a weighted sum of samples from the input vector.

x_{i}^{m,n} = ∑_{j} W_{ij}^{n}f_{j}^{n}(x^{m,n−1}),  (1)
or x^{m,n} = W̃^{n} · f^{n}(x^{m,n−1}) (in vector notation).  (2)
Find parameters p^{m} ≈ x^{m,N}  (3)
from data d^{m} = x^{m,0}.  (4)

Usually the non-linear functions f^{n} apply independently to each element of the vector. Functions are expected to be monotonic over the range 0 ≤ f(x) < f(x′) ≤ 1 for values 0 ≤ x < x′ ≤ 1. The derivative df(x)/dx should also be continuous. Usually, the shape is a sigmoid or linear. Because the notation presents no difficulty, I write this non-linear scalar function as a more general vector function.

I could also have reversed the order of linear and non-linear operators. A reversed order is equivalent to setting f^{1} and W̃^{N} to identity operations. This form (1) is somewhat easier to manipulate.

This nonlinear recursion can be abbreviated as

p^{m} ≈ x^{m,N}(d^{m}, W̃^{1}, …, W̃^{N}) = x^{m,N}.  (5)

Perturbations of an Objective Function

The best weights W̃^{n} are assumed to minimize the following least-squares objective function F, summed over all known pairs m of data measurements d^{m} and model parameters p^{m}.

min_{{W_{ij}^{n}}} F (W̃^{1}, …, W̃^{N}) = ∑_{m,k} [p_{k}^{m} − x_{k}^{m,N}(d^{m}, W̃^{1}, …, W̃^{N})]^{2} = ∑_{m} ∥p^{m} − x^{m,N}∥^{2}. (6)

A perturbation of the weights δW̃^{n} will result in a linearized perturbation δF of the objective function:

δF (W̃^{1}, …, W̃^{N}) = − ∑_{m,k} (p_{k}^{m} − x_{k}^{m,N})δx_{k}^{m,N} = − ∑_{m} (p^{m} − x^{m,N}) · δx^{m,N},  (7)
where δx^{m,0} = 0  (8)
and δx_{i}^{m,n} = ∑_{j} δW_{ij}^{n} · f_{j}^{n}(x^{m,n−1}) + ∑_{j} W_{ij}^{n} ∑_{k} \frac{∂}{∂x_{k}} f_{j}^{n}(x^{m,n−1})δx_{k}^{m,n−1}, (9)
or δx^{m,n} = δW̃^{n} · f^{n}(x^{m,n−1}) + W̃^{n} · ˜∇f^{n}(x^{m,n−1}) · δx^{m,n−1}.  (10)

Unperturbed variables retain their original reference values from the original non-linear forward transform (1).

The perturbations (9) of the vector elements δx^{m,n} are expressed as a linear function of perturbed weights δW̃^{n}. We can abbreviate the recursive equations (9) as a single linear transform G̃^{m,n}.

δx_{k}^{m,N} = ∑_{n,i,j} G_{kij}^{m,n}δW_{ij}^{n}  (11)
or δx^{m,N} = ∑_{n} G̃^{m,n} : δW̃^{n}.  (12)

Gradient optimization also requires the adjoint of this linearization. If the linearized forward transform is expressed as a matrix, then the adjoint transform is just the transpose of this matrix. A matrix would be unwieldy, but the recursive version of the adjoint equations is not.

δW_{ij}^{n} = ∑_{m} δx_{i}^{m,n}f_{j}^{n}(x^{m,n−1}),  (13)

or δW̃^{n} = ∑_{m} δx^{m,n}[f^{n}(x^{m,n−1})]^{∗} (outer product),  (14)
where δx^{m,N} = −(p^{m} − x^{m,N})δF  (15)
and δx_{k}^{m,n−1} = ∑_{j} \frac{∂}{∂x_{k}} f_{j}^{n}(x^{m,n−1}) ∑_{i} W_{ij}^{n}δx_{i}^{m,n},  (16)
or δx^{m,n−1} = [ ˜∇f^{n}(x^{m,n−1})]^{∗} · (W̃^{n})^{∗} · δx^{m,n}.  (17)

These perturbations do not equal those of the forward linearization. The adjoint recursion can also be abbreviated with the linear transform G̃^{m,n}.

δW_{ij}^{n} = ∑_{m,k} G_{kij}^{m,n}δx_{k}^{m,N},  (18)
or δW̃^{n} = (G̃^{m,n})^{∗} · δx^{m,N}.  (19)

If the linear transform G̃^{m,n} were written as a single large matrix, then indeed the matrix would be identical in the forward and adjoint equations (11) and (18). For optimization, fortunately, we need not construct this matrix explicitly (as would be required by singularvalue decomposition). Instead, we need only be able to multiply this linear transform or its adjoint by specific perturbations, using the recursions (9) and (16).

Optimization

The simplest neural network “training” algorithm adjusts the previous choice of weights by a scaled gradient. This recursive algorithm is called back-propagation.

1. Initialize each weight matrix W̃^{n}.

2. Calculate ΔW_{ij}^{n} = ∑_{m,k} G_{kij}^{m,n}[p_{k}^{m} − x_{k}^{m,N}(d^{m}, W̃^{1}, …, W̃^{N})], ΔW̃^{n} = (G̃^{m,n})^{∗} · (p^{m} − x^{m,N}).

3. Replace each W̃^{n} by W̃^{n} + ϵΔW̃^{n}.

4. Return to step 2.

To reduce the objective function, the perturbation reverses the sign of the gradient. The small scale factor ϵ is sometimes fixed a priori and never changed. If the scale factor is too small, then many consecutive steps may move in the same direction. If the scale factor is too large, the perturbations may increase rather than decrease the objective function and may even diverge. Although this algorithm is most commonly cited, we can easily do better. Let us turn to standard non-linear optimization methods.

Many steepest-descent algorithms would replace step 3 by a line search to find an optimum scale factor.

1. Initialize each weight matrix W̃^{n}.

2. Calculate ΔW̃^{n} as before.

3. Find α to minimize ∑_{m,k} [p_{k}^{m} − x_{k}^{m,N}(d^{m}, W̃^{1} + αΔW̃^{1}, …, W̃^{N} + αΔW̃^{N})]^{2}

4. Replace each W̃^{n} by W̃^{n} + αΔW̃^{n}.

5. Return to step 2. This revised algorithm is guaranteed to find a local minimum where the gradient is zero. Step sizes are large. The line search can use combinations of parabolic fitting and golden sections for speed and robustness.

A good estimate of the scale factor can be estimated without an explicit line search.

1. Initialize each W̃^{n}.

2. Calculate ΔW̃^{n} as before.

3. Calculate Δx^{m,N} = ∑_{n} G̃^{m,n} : ΔW̃^{n} .

4. Find α to minimize ∑_{m,k} [p_{k}^{m} − αΔx_{k}^{m,N}]^{2} , or equivalently α = (∑_{m,k} p_{k}^{m}Δx_{k}^{m,N})/ ∑_{m,k} Δx_{k}^{m,N}Δx_{k}^{m,N}).

5. Replace each W̃^{n} by W̃^{n} + αΔW̃^{n}.

6. Return to step 2. When the linearization is a good approximation (particularly in the vicinity of a mini-

mum), the scale factor will be very accurate. Each iteration will be much more efficient than a line search. If the scaled perturbation increases the objective function in early non-linear iterations, then a line search can be used until the linearization improves.

The convergence of these steepest descent algorithms should be improved by a PARTAN or Fletcher-Reeves algorithm, which retains and combines consecutive gradients. Neural network references use the word “momentum” to describe similar strategies, usually with invariable scale factors.

An even more efficient alternative is to solve the linearized least-squares problem fully in each iteration — a Gauss-Newton approach:

1. Initialize each W̃^{n}.

2. Find the perturbations {w̃^{1}, …, w̃^{N}} that minimize ∑_{m,k} [p_{k}^{m} − x_{k}^{m,N}(d^{m}, W̃^{1}, …, W̃^{N}) − ∑_{n,i,j} G_{kij}^{m,n}w_{ij}^{n}]^{2}.

3. Replace each W̃^{n} by W̃^{n} + w̃^{n}.

4. Return to step 2.

Since the objective function in step 2 is a fully quadratic function of the perturbations w̃^{n}, we can use iterative least-squares methods like conjugate gradients.

If a steepest descent algorithm were applied with an unlimited number of infinitesimal perturbations, then the changing weights would continuously decrease the objective function until a local minimum was reached. Visualize following a path that is directly downhill at every point. The path cannot ascend, no matter what may be beyond the next rise. Practical descent algorithms take large step sizes and may step over a small local increase in the objective function, to find another minimum beyond.

To increase the chances of finding the global minimum with the pseudo-quadratic objective function (6), we could initialize with different initial weights and discard suboptimum local minima. If different weights consistently lead to the same solution, then the objective function is probably convex and has only one global minimum.

References

[1] David G. Luenberger. Introduction to Linear and Nonlinear Programming. Addison Wesley, 1973.