../ Data Science
-rw-r--r--aguang3.9 KiB4 min read

modified

Multi-Layer Perceptron and Back-Propagation Algorithm

Perceptron

In machine learning, perceptron is a binary classifier, which calculates a linear combination and outputs 1 or -1.

x0 x[0] = 1 y ∑ x0->y w0 f f y->f x1 x[1] x1->y w[1] xi ... xi->y w[i] xn x[n] xn->y w[n] o o f->o

The takes an vector X=(x1⋯xn)X = (x_1 \cdots x_n) as the input, and calculates o=f(∑i=0nwixi)o = f(\sum_{i = 0}^n w_i x_i), where ff is a threshold function.

f(x)={+1x>0−1otherwise.f(x) = \begin{cases} +1 & x > 0 \\ -1 & \text{otherwise}. \end{cases}

Another vector W=(w0⋯xn)W = (w_0 \cdots x_n) is the parameters. For any linearly separable problems, we can always find a suitable parameter WW to make the perceptron works.

Gradient Descent

Gradient descent is the key of how to find suitable parameters WW for the perceptron to solve a specific problem.

For given multivariable function ff, the gradient ∇f\nabla f is a vector-valued function and the result includes all partial derivatives of ff at current point.

∇f=(∂F∂x0⋯∂F∂xn)\nabla f = ( \frac{\partial F}{\partial x_0} \cdots \frac{\partial F}{\partial x_n} )

Let's say γ\gamma is a small enough number. For any aa and b=a−γ∇F(a)b = a - \gamma \nabla F(a), we have: F(b)≤F(a)F(b) \leq F(a).

Perceptron Learning Algorithm

For a given trainning instance X=(x1⋯xn)X = (x_1 \cdots x_n) and the classification t∈{−1,1} t \in \{-1, 1 \}.

Let's say the current parameter is W=(w0⋯wn)W = (w_0 \cdots w_n).

Using the current state of the perceptron, you can calculate a result:

  • y=∑i=0nwixiy = \sum_{i = 0}^n w_i x_i
  • o=f(y)∈{−1,1}o = f(y) \in \{ -1, 1 \}

If t=ot = o, that means the perceptron already works well for the given instance. Or, we've already knew that whether we should make the calculated yy bigger or smaller.

Since ∇y(w0⋯wn)=(x0⋯xn)\nabla y(w_0 \cdots w_n) = (x_0 \cdots x_n),

  • If o=−1o = -1, then yy is expected to be greater and we can replace wiw_i with wi‾=wi+γxi\overline{w_i} = w_i + \gamma x_i.

  • If o=+1o = +1, then yy is expected to be smaller and we can replace wiw_i with wi‾=wi−γxi\overline{w_i} = w_i - \gamma x_i.

In general, we can always replace wiw_i with wi‾=wi+γ(t−o)xi\overline{w_i} = w_i + \gamma (t - o) x_i to make the perceptron better.

Multi-Layer Perceptron

The single perceptron can only solve linearly separable problems. To deal with more complicated classification problems, we have multi-layer perceptron.

x1 x1 y1 f1(∑) x1->y1 y2 f2(∑) x1->y2 y3 f3(∑) x1->y3 x2 x2 x2->y1 x2->y2 x2->y3 y4 f4(∑) y1->y4 y5 f5(∑) y1->y5 y2->y4 y2->y5 y3->y4 y3->y5 y6 f6(∑) y4->y6 y5->y6 o o y6->o

The basic idea of multi-layer perception is just stacking a sort of perceptrons and make it as a network. For example, in the case showing above:

  • x1x_1 and x2x_2 are called input layer.
  • (f1,f2,f3)(f_1, f_2, f_3) and (f4,f5)(f_4, f_5) are two hidden layers.
  • f6f6 is called output layer.
  • In each directed edge, there is a parameter wi,jw_{i, j} as familiar as the single perceptron.

Back-Propagation Algorithm

In multi-layer perceptron, we use the same gradient decent strategy to update parameters, which is called backpropagation algorithm. And there are two steps:

  • Familiar with Δ=t−o\Delta = t - o in perceptron learning algorithm, it reversely calculates the Δf\Delta f for each perceptron.

  • Then, it uses the same strategy to update w‾\overline{w} for each edge.

Example.

Here is an example of digital recognizer based on multi-layer perceptron, of which the accuracy is about 98%.

COMMAND INTERFACE

↑ ↓ navigate · Enter execute · Esc exit · try “whoami”

Loading filesystem…

:help aguang.xyz

A personal website disguised as an operating system.

Ctrl / Cmd + K
Command palette + full-text search
Tab / Shift + Tab
Move between links and controls
Enter
Open a focused link or search result
↑ / ↓ in search
Navigate search results
In a directory filter
Enter/Done or ↓ focuses a result; Esc clears the filter
Esc
Clear a search or close a window