Feedforward algorithm: Difference between revisions
No edit summary |
|||
| Line 1: | Line 1: | ||
The '''feedforward algorithm''' is | [[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|]] | ||
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 | \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_{ | w_{1,1} & w_{1,2} & \cdots & w_{0,n} \\ | ||
w_{1 | w_{2,1} & w_{2,2} & \cdots & w_{1,n} \\ | ||
\vdots & \vdots & \ddots & \vdots \\ | \vdots & \vdots & \ddots & \vdots \\ | ||
w_{m, | w_{m,1} & w_{m,2} & \cdots & w_{m,n} | ||
\end{pmatrix} | \end{pmatrix} | ||
\begin{pmatrix} | \begin{pmatrix} | ||
a^{( | a^{(l)}_1 \\ | ||
a^{( | a^{(l)}_2 \\ | ||
\vdots \\ | \vdots \\ | ||
a^{( | a^{(l)}_n | ||
\end{pmatrix} | \end{pmatrix} | ||
+ | + | ||
\begin{pmatrix} | \begin{pmatrix} | ||
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

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