Jump to content

Feedforward algorithm: Difference between revisions

From Wikibase
Created page with "The '''feedforward algorithm''' is an algorithm used in a multi-layer artificial neural network (ANN) to calculate the value of the next layer of artificial neurons. == Mathematical formulation == thumbnail| Given an input vector $\vec a^{(0)} \in \mathbb{R}^n$ consisting values of the artificial neurons of layer 0, a weight matrix $\mathbf{W} \in \mathbb{R}^m \times \mathbb{R}^n$, and a bias vector $\vec b \i..."
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
The '''feedforward algorithm''' is an [[algorithm]] used in a multi-layer [[artificial neural network (ANN)]] to calculate the value of the next layer of [[artificial neuron]]s.
[[Category:Artificial neural network]]
The '''feedforward algorithm''' is the simplest [[algorithm]] connecting [[artificial neuron#Layer_composition|two layers]] of a multi-layer [[artificial neural network (ANN)]], feeding the output of a layer to the next as input.


== Mathematical formulation ==
== Mathematical formulation ==


[[File:Layer-layer calculation in ANN.png|thumbnail|]]
[[File:Layer-layer calculation in ANN.png|thumbnail|]]
Given an input vector $\vec a^{(0)} \in \mathbb{R}^n$ consisting values of the [[artificial neurons]] of layer 0, a weight matrix $\mathbf{W} \in \mathbb{R}^m \times \mathbb{R}^n$, and a bias vector $\vec b \in \mathbb{R}^m$, the value of the next layer
Let $\vec a^{(l)} \in \mathbb{R}^n$ be the [[artificial neuron#Layer_composition|'''layer activation vector''']] of layer $l$, then the '''input vector''' for the next layer ($l+1$)


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


Where $f$ is the activation function, often the [[sigmoid function]].
=== Basic form ===
 
In [[artificial neuron#Mathematical_representation|basic form]], where each neuron satisfies
 
{{#content:Q3075|noNote}}
 
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:
In matrix form:


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


=== Python ===
=== Python (basic form) ===


<syntaxhighlight lang="python">
<syntaxhighlight lang="python">

Latest revision as of 14:38, 16 November 2026

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