Jump to content

Feedforward algorithm

From Wikibase

Languages: English · français · Esperanto

The feedforward algorithm is the simplest algorithm connecting two layers of a multi-layer artificial neural network (ANN), feeding the output of a layer to the next as input.

Mathematical formulation

· Open in a new tab

Let $\vec a^{(l)} \in \mathbb{R}^n$ be the layer activation vector of layer $l$, then the input vector for the next layer ($l+1$)

$$ \vec x^{(l+1)}=\vec a^{(l)} $$

Basic form

In basic form, where each neuron satisfies

$$\begin{gathered}a = f\left(z \right)\\ \text{Basic form}: z = \sum_{i=1}^{n} w_i x_i + b\end{gathered}$$

then with feedforward from layer $l$ ($m$ neurons) to layer $l+1$ ($n$ neurons),

$$ \vec a^{(l+1)} = f(\mathbf{W}\vec a^{(l)} + \vec b) $$

where $\mathbf{W} \in \mathbb{R}^m \times \mathbb{R}^n$ is the weight matrix, and $\vec b \in \mathbb{R}^m$ the bias vector, both of layer $l+1$, and $f$ is the activation function, often the sigmoid function.

In matrix form:

$$ \vec a^{(l+1)} = f \left( \begin{pmatrix} w_{1,1} & w_{1,2} & \cdots & w_{0,n} \\ w_{2,1} & w_{2,2} & \cdots & w_{1,n} \\ \vdots & \vdots & \ddots & \vdots \\ w_{m,1} & w_{m,2} & \cdots & w_{m,n} \end{pmatrix} \begin{pmatrix} a^{(l)}_1 \\ a^{(l)}_2 \\ \vdots \\ a^{(l)}_n \end{pmatrix} + \begin{pmatrix} b_1 \\ b_2 \\ \vdots \\ b_m \end{pmatrix} \right) $$

Implementation

Python (basic form)

def feedforward(self, a):
    """Feedforward input vector a to a_1"""
    for b, w in zip(self.biases, self.weights):
        a_1 = sigmoid(np.dot(w, a) + b)
    return a_1