Mathematics of artificial neural networks

From HandWiki
Main page: Artificial neural network

An artificial neural network (ANN) combines biological principles with advanced statistics to solve problems in domains such as pattern recognition and game-play. ANNs adopt the basic model of neuron analogues connected to each other in a variety of ways.

Structure

Neuron

A neuron with label [math]\displaystyle{ j }[/math] receiving an input [math]\displaystyle{ p_j(t) }[/math] from predecessor neurons consists of the following components:[1]

  • an activation [math]\displaystyle{ a_j(t) }[/math], the neuron's state, depending on a discrete time parameter,
  • an optional threshold [math]\displaystyle{ \theta_j }[/math], which stays fixed unless changed by learning,
  • an activation function [math]\displaystyle{ f }[/math] that computes the new activation at a given time [math]\displaystyle{ t+1 }[/math] from [math]\displaystyle{ a_j(t) }[/math], [math]\displaystyle{ \theta_j }[/math] and the net input [math]\displaystyle{ p_j(t) }[/math] giving rise to the relation
[math]\displaystyle{ a_j(t+1) = f(a_j(t), p_j(t), \theta_j), }[/math]
  • and an output function [math]\displaystyle{ f_\text{out} }[/math] computing the output from the activation
[math]\displaystyle{ o_j(t) = f_\text{out}(a_j(t)). }[/math]

Often the output function is simply the identity function.

An input neuron has no predecessor but serves as input interface for the whole network. Similarly an output neuron has no successor and thus serves as output interface of the whole network.

Propagation function

The propagation function computes the input [math]\displaystyle{ p_j(t) }[/math] to the neuron [math]\displaystyle{ j }[/math] from the outputs [math]\displaystyle{ o_i(t) }[/math]and typically has the form[1]

[math]\displaystyle{ p_j(t) = \sum_i o_i(t) w_{ij}. }[/math]

Bias

A bias term can be added, changing the form to the following:[2]

[math]\displaystyle{ p_j(t) = \sum_i o_i(t) w_{ij}+ w_{0j}, }[/math] where [math]\displaystyle{ w_{0j} }[/math] is a bias.

Neural networks as functions

Neural network models can be viewed as defining a function that takes an input (observation) and produces an output (decision) [math]\displaystyle{ \textstyle f : X \rightarrow Y }[/math] or a distribution over [math]\displaystyle{ \textstyle X }[/math] or both [math]\displaystyle{ \textstyle X }[/math] and [math]\displaystyle{ \textstyle Y }[/math]. Sometimes models are intimately associated with a particular learning rule. A common use of the phrase "ANN model" is really the definition of a class of such functions (where members of the class are obtained by varying parameters, connection weights, or specifics of the architecture such as the number of neurons, number of layers or their connectivity).

Mathematically, a neuron's network function [math]\displaystyle{ \textstyle f(x) }[/math] is defined as a composition of other functions [math]\displaystyle{ \textstyle g_i(x) }[/math], that can further be decomposed into other functions. This can be conveniently represented as a network structure, with arrows depicting the dependencies between functions. A widely used type of composition is the nonlinear weighted sum, where [math]\displaystyle{ \textstyle f (x) = K \left(\sum_i w_i g_i(x)\right) }[/math], where [math]\displaystyle{ \textstyle K }[/math] (commonly referred to as the activation function[3]) is some predefined function, such as the hyperbolic tangent, sigmoid function, softmax function, or rectifier function. The important characteristic of the activation function is that it provides a smooth transition as input values change, i.e. a small change in input produces a small change in output. The following refers to a collection of functions [math]\displaystyle{ \textstyle g_i }[/math] as a vector [math]\displaystyle{ \textstyle g = (g_1, g_2, \ldots, g_n) }[/math].

ANN dependency graph

This figure depicts such a decomposition of [math]\displaystyle{ \textstyle f }[/math], with dependencies between variables indicated by arrows. These can be interpreted in two ways.

The first view is the functional view: the input [math]\displaystyle{ \textstyle x }[/math] is transformed into a 3-dimensional vector [math]\displaystyle{ \textstyle h }[/math], which is then transformed into a 2-dimensional vector [math]\displaystyle{ \textstyle g }[/math], which is finally transformed into [math]\displaystyle{ \textstyle f }[/math]. This view is most commonly encountered in the context of optimization.

The second view is the probabilistic view: the random variable [math]\displaystyle{ \textstyle F = f(G) }[/math] depends upon the random variable [math]\displaystyle{ \textstyle G = g(H) }[/math], which depends upon [math]\displaystyle{ \textstyle H=h(X) }[/math], which depends upon the random variable [math]\displaystyle{ \textstyle X }[/math]. This view is most commonly encountered in the context of graphical models.

The two views are largely equivalent. In either case, for this particular architecture, the components of individual layers are independent of each other (e.g., the components of [math]\displaystyle{ \textstyle g }[/math] are independent of each other given their input [math]\displaystyle{ \textstyle h }[/math]). This naturally enables a degree of parallelism in the implementation.

Two separate depictions of the recurrent ANN dependency graph

Networks such as the previous one are commonly called feedforward, because their graph is a directed acyclic graph. Networks with cycles are commonly called recurrent. Such networks are commonly depicted in the manner shown at the top of the figure, where [math]\displaystyle{ \textstyle f }[/math] is shown as dependent upon itself. However, an implied temporal dependence is not shown.

Backpropagation

Backpropagation training algorithms fall into three categories:

Algorithm

Let [math]\displaystyle{ N }[/math] be a network with [math]\displaystyle{ e }[/math] connections, [math]\displaystyle{ m }[/math] inputs and [math]\displaystyle{ n }[/math] outputs.

Below, [math]\displaystyle{ x_1,x_2,\dots }[/math] denote vectors in [math]\displaystyle{ \mathbb{R}^m }[/math], [math]\displaystyle{ y_1,y_2,\dots }[/math] vectors in [math]\displaystyle{ \mathbb{R}^n }[/math], and [math]\displaystyle{ w_0, w_1, w_2, \ldots }[/math] vectors in [math]\displaystyle{ \mathbb{R}^e }[/math]. These are called inputs, outputs and weights, respectively.

The network corresponds to a function [math]\displaystyle{ y = f_N(w, x) }[/math] which, given a weight [math]\displaystyle{ w }[/math], maps an input [math]\displaystyle{ x }[/math] to an output [math]\displaystyle{ y }[/math].

In supervised learning, a sequence of training examples [math]\displaystyle{ (x_1,y_1), \dots, (x_p, y_p) }[/math] produces a sequence of weights [math]\displaystyle{ w_0, w_1, \dots, w_p }[/math] starting from some initial weight [math]\displaystyle{ w_0 }[/math], usually chosen at random.

These weights are computed in turn: first compute [math]\displaystyle{ w_i }[/math] using only [math]\displaystyle{ (x_i, y_i, w_{i-1}) }[/math] for [math]\displaystyle{ i = 1, \dots, p }[/math]. The output of the algorithm is then [math]\displaystyle{ w_p }[/math], giving a new function [math]\displaystyle{ x \mapsto f_N(w_p, x) }[/math]. The computation is the same in each step, hence only the case [math]\displaystyle{ i = 1 }[/math] is described.

[math]\displaystyle{ w_1 }[/math] is calculated from [math]\displaystyle{ (x_1, y_1, w_0) }[/math] by considering a variable weight [math]\displaystyle{ w }[/math] and applying gradient descent to the function [math]\displaystyle{ w\mapsto E(f_N(w, x_1), y_1) }[/math] to find a local minimum, starting at [math]\displaystyle{ w = w_0 }[/math].

This makes [math]\displaystyle{ w_1 }[/math] the minimizing weight found by gradient descent.

Learning pseudocode

To implement the algorithm above, explicit formulas are required for the gradient of the function [math]\displaystyle{ w \mapsto E(f_N(w, x), y) }[/math] where the function is [math]\displaystyle{ E(y,y')= |y-y'|^2 }[/math].

The learning algorithm can be divided into two phases: propagation and weight update.

Propagation

Propagation involves the following steps:

  • Propagation forward through the network to generate the output value(s)
  • Calculation of the cost (error term)
  • Propagation of the output activations back through the network using the training pattern target to generate the deltas (the difference between the targeted and actual output values) of all output and hidden neurons.

Weight update

For each weight:

  • Multiply the weight's output delta and input activation to find the gradient of the weight.
  • Subtract the ratio (percentage) of the weight's gradient from the weight.

The learning rate is the ratio (percentage) that influences the speed and quality of learning. The greater the ratio, the faster the neuron trains, but the lower the ratio, the more accurate the training. The sign of the gradient of a weight indicates whether the error varies directly with or inversely to the weight. Therefore, the weight must be updated in the opposite direction, "descending" the gradient.

Learning is repeated (on new batches) until the network performs adequately.

Pseudocode

Pseudocode for a stochastic gradient descent algorithm for training a three-layer network (one hidden layer):

initialize network weights (often small random values)
do
    for each training example named ex do
        prediction = neural-net-output(network, ex)  // forward pass
        actual = teacher-output(ex)
        compute error (prediction - actual) at the output units
        compute [math]\displaystyle{ \Delta w_h }[/math] for all weights from hidden layer to output layer  // backward pass
        compute [math]\displaystyle{ \Delta w_i }[/math] for all weights from input layer to hidden layer   // backward pass continued
        update network weights // input layer not modified by error estimate
until error rate becomes acceptably low
return the network

The lines labeled "backward pass" can be implemented using the backpropagation algorithm, which calculates the gradient of the error of the network regarding the network's modifiable weights.[5]

References

  1. 1.0 1.1 Zell, Andreas (2003). "chapter 5.2" (in German). Simulation neuronaler Netze (1st ed.). Addison-Wesley. ISBN 978-3-89319-554-1. OCLC 249017987. 
  2. DAWSON, CHRISTIAN W (1998). "An artificial neural network approach to rainfall-runoff modelling". Hydrological Sciences Journal 43 (1): 47–66. doi:10.1080/02626669809492102. 
  3. "The Machine Learning Dictionary". http://www.cse.unsw.edu.au/~billw/mldict.html#activnfn. 
  4. M. Forouzanfar; H. R. Dajani; V. Z. Groza; M. Bolic; S. Rajan (July 2010). "Comparison of Feed-Forward Neural Network Training Algorithms for Oscillometric Blood Pressure Estimation". 4th Int. Workshop Soft Computing Applications. Arad, Romania: IEEE. https://www.researchgate.net/publication/224173336. 
  5. Werbos, Paul J. (1994). The Roots of Backpropagation. From Ordered Derivatives to Neural Networks and Political Forecasting. New York, NY: John Wiley & Sons, Inc.