The Wayback Machine - https://web.archive.org/web/20241009230943/https://www.geeksforgeeks.org/understanding-multi-layer-feed-forward-networks/
Open In App

Understanding Multi-Layer Feed Forward Networks

Last Updated : 16 Oct, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Let’s understand how errors are calculated and weights are updated in backpropagation networks(BPNs).

Consider the following network in the below figure.

Backpropagation Network (BPN)

The network in the above figure is a simple multi-layer feed-forward network or backpropagation network. It contains three layers, the input layer with two neurons x1 and x2, the hidden layer with two neurons z1 and z2 and the output layer with one neuron yin. 

Now let’s write down the weights and bias vectors for each neuron. 

Note: The weights are taken randomly.

Input layer: i/p – [x1 x2] = [0 1]

Here since it is the input layer only the input values are present.

Hidden layer: z1 – [v11 v21 v01] = [0.6 -0.1 03]

Here v11 refers to the weight of first input x1 on z1, v21 refers to the weight of second input x2 on z1 and v01 refers to the bias value on z1.

z2 – [v12 v22 v02] = [-0.3 0.4 0.5]

Here v12 refers to the weight of first input x1 on z2, v22 refers to the weight of second input x2 on z2 and v02 refers to the bias value on z2.

Output layer: yin – [w11 w21 w01] = [0.4 0.1 -0.2]

Here w11 refers to the weight of first neuron z1 in a hidden layer on yin, w21 refers to the weight of second neuron z2 in a hidden layer on yin and w01 refers to the bias value on yin. Let’s consider three variables, k which refers to the neurons in the output layer, ‘j’ which refers to the neurons in the hidden layer and ‘i’ which refers to the neurons in the input layer.

Therefore, 

k = 1

j = 1, 2(meaning first neuron and second neuron in hidden layer)

i = 1, 2(meaning first and second neuron in the input layer)

Below are some conditions to be followed in BPNs.

Conditions/Constraints:

  1. In BPN, the activation function used should be differentiable.
  2. The input for bias is always 1.

To proceed with the problem, let:

Target value, t = 1

Learning rate, α = 0.25

Activation function = Binary sigmoid function

Binary sigmoid function, f(x) = (1+e-x)-1       eq. (1)

And, f'(x) = f(x)[1-f(x)]       eq. (2)

There are three steps to solve the problem:

  1. Computing the output, y.
  2. Backpropagation of errors, i.e., between output and hidden layer, hidden and input layer.
  3. Updating weights.

Step 1:

The value y is calculated by finding yin and applying the activation function.

yin is calculated as:

yin = w01 + z1*w11 + z2*w21      eq. (3)

Here, z1 and z2 are the values from hidden layer, calculated by finding zin1, zin2 and applying activation function to them.

zin1 and zin2 are calculated as:

zin1 = v01 + x1*v11 + x2*v21   eq. (4)

zin2 = v02 + x1*v12 + x2*v22   eq. (5)

From (4)

zin1 = 0.3 + 0*0.6 + 1*(-0.1)

zin1 = 0.2

z1 = f(zin1) = (1+e-0.2)-1  From (1)

z1 = 0.5498

From (5)

zin2 = 0.5 + 0*(-0.3) + 1*0.4

zin2 = 0.9

z2 = f(zin2) = (1+e-0.9)-1    From (1)

z2 = 0.7109

From (3)

yin = (-0.2) + 0.5498*0.4 + 0.7109*0.1

yin = 0.0910

y = f(yin) = (1+e-0.0910)-1     From (1)

y = 0.5227

Here, y is not equal to the target ‘t’, which is 1. And we proceed to calculate the errors and then update weights from them in order to achieve the target value.

Step 2:

(a) Calculating the error between output and hidden layer

Error between output and hidden layer is represented as δk, where k represents the neurons in output layer as mentioned above. The error is calculated as:

δk = (tk – yk) * f'(yink)               eq. (6)

where, f'(yink) = f(yink)[1 – f(yink)]        From (2)

Since k = 1 (Assumed above),

δ = (t – y) f'(yin)                       eq. (7)

where, f'(yin) = f(yin)[1 – f(yin)]

f'(yin) = 0.5227[1 – 0.5227]

f'(yin) = 0.2495

Therefore, 

δ = (1 – 0.5227) * 0.2495           From (7)

δ = 0.1191, is the error

Note: (Target – Output) i.e., (t – y) is the error in the output not in the layer. Error in a layer is contributed by different factors like weights and bias.

(b) Calculating the error between hidden and input layer

Error between hidden and input layer is represented as δj, where j represents the number of neurons in the hidden layer as mentioned above. The error is calculated as:

δj = δinj  * f'(zinj)            eq. (8)

where, 

δinj = ∑k=1 to n (δk * wjk)    eq. (9)

f'(zinj) = f(zinj)[1 – f(zinj)]    eq. (10)

Since k = 1(Assumed above) eq. (9) becomes:

δinj = δ * wj1       eq. (11)

As j = 1, 2, we will have one error values for each neuron and total of 2 errors values.

δ1 = δin1  * f'(zin1)        eq. (12),  From (8)

δin1 = δ * w11                 From (11)

δin1 = 0.1191 * 0.4        From weights vectors

δin1 = 0.04764               

f'(zin1) = f(zin1)[1 – f(zin1)]

f'(zin1) = 0.5498[1 – 0.5498]         As f(zin1) = z1

f'(zin1) = 0.2475

Substituting in (12)

δ1 = 0.04674 * 0.2475 = 0.0118

δ2 = δin2  * f'(zin2)        eq. (13), From (8)

δin2 = δ * w21                 From (11)

δin2 = 0.1191 * 0.1        From weights vectors

δin2 = 0.0119              

f'(zin2) = f(zin2)[1 – f(zin2)]

f'(zin2) = 0.7109[1 – 0.7109]         As f(zin2) = z2

f'(zin2) = 0.2055

Substituting in (13)

δ2 = 0.0119 * 0.2055 = 0.00245

The errors have been calculated, the weights have to be updated using these error values.

Step 3:

The formula for updating weights for output layer is:

wjk(new) = wjk(old) + Δwjk         eq. (14)

where, Δwjk = α * δk * zj           eq. (15)

Since k = 1, (15) becomes: 

Δwjk = α * δ * zi                        eq. (16)                             

The formula for updating weights for hidden layer is:

vij(new) = vij(old) + Δvij           eq. (17)

where, Δvi = α * δj * xi           eq. (18)

From (14) and (16)

w11(new) = w11(old) + Δw11 = 0.4 + α * δ * z1  =  0.4 + 0.25 * 0.1191 * 0.5498 = 0.4164

w21(new) = w21(old) + Δw21 = 0.1 + α * δ * z2 = 0.1 + 0.25 * 0.1191 * 0.7109 = 0.12117

w01(new) = w01(old) + Δw01 = (-0.2) + α * δ * bias = (-0.2) + 0.25 * 0.1191 * 1 = -0.1709, kindly note the 1 taken here is input considered for bias as per the conditions.

These are the updated weights of the output layer.

From (17) and (18)

v11(new) = v11(old) + Δv11 = 0.6 +  α * δ1 * x1 = 0.6 + 0.25 * 0.0118 * 0 = 0.6

v21(new) = v21(old) + Δv21 = (-0.1) +  α * δ1 * x2 = (-0.1) + 0.25 * 0.0118 * 1 = 0.00295

v01(new) = v01(old) + Δv01 = 0.3 +  α * δ1 * bias = 0.3 + 0.25 * 0.0118 * 1 = 0.00295, kindly note the 1 taken here is input considered for bias as per the conditions.

v12(new) = v12(old) + Δv12 = (-0.3) +  α * δ2 * x1 = (-0.3) + 0.25 * 0.00245 * 0 = -0.3

v22(new) = v22(old) + Δv22 = 0.4 +  α * δ2 * x2 = 0.4 + 0.25 * 0.00245 * 1 = 0.400612

v02(new) = v02(old) + Δv02 = 0.5 +  α * δ2 * bias = 0.5 + 0.25 * 0.00245 * 1 = 0.500612, kindly note the 1 taken here is input considered for bias as per the conditions.

These are all the updated weights of the hidden layer.

These three steps are repeated until the output ‘y’ is equal to the target ‘t’.

This is how the BPNs work. The backpropagation in BPN refers to that the error in the present layer is used to update weights between the present and previous layer by backpropagating the error values.



Previous Article
Next Article

Similar Reads

What's the difference of stateless LSTM and a normal feed-forward NN?
Answer: Stateless LSTM disregards past sequences, while a feed-forward neural network lacks internal memory and processes inputs sequentially.Here is a comparison between stateless LSTM and a normal feed-forward NN: AspectStateless LSTMFeed-Forward Neural Network (NN)ArchitectureIncorporates Long Short-Term Memory (LSTM) cells that allow capturing
2 min read
Understanding the Forward Function Output in PyTorch
PyTorch, an open-source machine learning library, is widely used for applications such as computer vision and natural language processing. One of the core components of PyTorch is the forward() function, which plays a crucial role in defining how data passes through a neural network. This article delves into the intricacies of the forward() functio
5 min read
What is Forward Propagation in Neural Networks?
Feedforward neural networks stand as foundational architectures in deep learning. Neural networks consist of an input layer, at least one hidden layer, and an output layer. Each node is connected to nodes in the preceding and succeeding layers with corresponding weights and thresholds. In this article, we will explore what is forward propagation an
8 min read
Fully Connected Layer vs Convolutional Layer
Confusion between Fully Connected Layers (FC) and Convolutional Layers is common due to terminology overlap. In CNNs, convolutional layers are used for feature extraction followed by FC layers for classification that makes it difficult for beginners to distinguish there roles. This article compares Fully Connected Layers (FC) and Convolutional Laye
4 min read
Difference Between an Embedding Layer and a Dense Layer
In neural networks, both embedding and dense layers serve distinct purposes and are fundamental in different types of network architectures. An embedding layer is primarily used for mapping high-dimensional categorical data into a lower-dimensional space, while a dense layer, also known as a fully connected layer, is a standard layer that processes
4 min read
Multi-Layer Perceptron Learning in Tensorflow
In this article, we will understand the concept of a multi-layer perceptron and its implementation in Python using the TensorFlow library. Multi-layer Perceptron Multi-layer perception is also known as MLP. It is fully connected dense layers, which transform any input dimension to the desired dimension. A multi-layer perception is a neural network
5 min read
Classification Using Sklearn Multi-layer Perceptron
A key machine learning method that belongs to the class of artificial neural networks is classification using Multi-Layer Perceptrons (MLP). It is a flexible and effective method for tackling a variety of classification problems, including text classification and picture recognition. Traditional linear classifiers might not be up to the challenge,
7 min read
Multi-layer Perceptron a Supervised Neural Network Model using Sklearn
An artificial neural network (ANN), often known as a neural network or simply a neural net, is a machine learning model that takes its cues from the structure and operation of the human brain. It is a key element in machine learning's branch known as deep learning. Interconnected nodes, also referred to as artificial neurons or perceptrons, are arr
11 min read
Multi-Hidden layer neural network with the mlp method in the caret package
Neural networks are a foundational element of deep learning, capable of modeling complex patterns in data. A neural network with multiple hidden layers, also known as a deep neural network, can capture intricate relationships in the data more effectively than a single-layer network. This article will cover the theory behind multi-hidden layer neura
4 min read
Multi-Layer Perceptrons (MLP) in R
In the world of machine learning, Multi-Layer Perceptrons (MLP) are a popular type of artificial neural network used for various tasks such as classification and regression. MLPs are versatile and can model complex patterns in data. Here, we’ll break down what MLPs are and how you can implement them using R for data analysis. What is a Multi-Layer
4 min read
What is the Difference between a "Cell" and a "Layer" within Neural Networks?
Answer: In neural networks, a "cell" refers to the basic processing unit within a recurrent neural network (RNN), such as a long short-term memory (LSTM) cell, while a "layer" is a structural component comprising interconnected neurons in the network architecture, including convolutional layers, dense layers, etc.In neural networks, both "cell" and
1 min read
What is a Projection Layer in the Context of Neural Networks?
A projection layer in neural networks refers to a layer that transforms input data into a different space, typically either higher or lower-dimensional, depending on the design and goals of the neural network. This transformation is generally linear and is often achieved using a fully connected layer (also known as a dense layer) without an activat
5 min read
Understanding of LSTM Networks
This article talks about the problems of conventional RNNs, namely, the vanishing and exploding gradients, and provides a convenient solution to these problems in the form of Long Short Term Memory (LSTM). Long Short-Term Memory is an advanced version of recurrent neural network (RNN) architecture that was designed to model chronological sequences
9 min read
Basic Understanding of Bayesian Belief Networks
Bayesian Belief Network is a graphical representation of different probabilistic relationships among random variables in a particular set. It is a classifier with no dependency on attributes i.e it is condition independent. Due to its feature of joint probability, the probability in Bayesian Belief Network is derived, based on a condition — P(attri
4 min read
Understanding Bayesian Networks: Modeling Probabilistic Relationships Between Variables
Bayesian networks, also known as belief networks or Bayesian belief networks (BBNs), are powerful tools for representing and reasoning about uncertain knowledge. These networks use a graphical structure to encode probabilistic relationships among variables, making them invaluable in fields such as artificial intelligence, bioinformatics, and decisi
4 min read
Linear Regression vs. Neural Networks: Understanding Key Differences
Linear Regression and Neural Networks are two fundamental techniques in the machine learning toolkit. Linear Regression is a simple, yet powerful, statistical method for modeling the relationship between a dependent variable and one or more independent variables. Neural Networks, on the other hand, are a class of models inspired by the human brain,
5 min read
Signed Networks in Social Networks
Prerequisite: Introduction to Social Networks In Social Networks, Network is of 2 types- Unsigned Network and Signed Network. In the unsigned network, there are no signs between any nodes, and in the signed network, there is always a sign between 2 nodes either + or -. The '+' sign indicates friendship between 2 nodes and the '-' sign indicates enm
4 min read
Differences Between Bayesian Networks and Neural Networks
Bayesian networks and neural networks are two distinct types of graphical models used in machine learning and artificial intelligence. While both models are designed to handle complex data and make predictions, they differ significantly in their theoretical foundations, operational mechanisms, and applications. This article will delve into the diff
9 min read
Difference between Backward and Forward chaining
Forward chaining: Forward chaining starts with the available data and user inference rules to extract more data from an end-user until the goal is reached. The reasoning applied to this information to obtain a logical conclusion. It is a system given one or more condition in which system search and the rule knowledge base each condition and rules t
2 min read
Forward Chaining and Backward Chaining inference in Rule-Based Systems
Rule-based systems are a cornerstone of artificial intelligence, enabling machines to make decisions based on a set of predefined rules. These systems utilize logical inferences to derive conclusions from given data. Two primary methods of inference in rule-based systems are forward chaining and backward chaining. This article explores the mechanis
5 min read
Deep Neural net with forward and back propagation from scratch - Python
This article aims to implement a deep neural network from scratch. We will implement a deep neural network containing two input layers, a hidden layer with four units and one output layer. The implementation will go from scratch and the following steps will be implemented. Algorithm:1. Loading and visualizing the input data2. Deciding the shapes of
6 min read
Forward State Space Planning (FSSP) in AI
Artificial Intelligence (AI) has revolutionized many fields, from robotics and natural language processing to game-playing and autonomous systems. One of the key aspects of AI is planning, which involves making decisions to achieve a goal based on a set of possible actions. Forward State Space Planning (FSSP) is a crucial method in the planning dom
8 min read
Visualizing representations of Outputs/Activations of each CNN layer
Convolutional neural networks are very powerful in image classification and recognition tasks. CNN models learn features of the training images with various filters applied at each layer. The features learned at each convolutional layer significantly vary. It is an observed fact that initial layers predominantly capture edges, the orientation of im
5 min read
Hidden Layer Perceptron in TensorFlow
In this article, we will learn about hidden layer perceptron. A hidden layer perceptron is nothing but a hi-fi terminology for a neural network with one or more hidden layers. The purpose which is being served by these hidden layers is that they help to learn complex and non-linear functions for a task. The above image is the simplest representatio
5 min read
Single Layer Perceptron in TensorFlow
In this article, we will be understanding the single-layer perceptron and its implementation in Python using the TensorFlow library. Neural Networks work in the same way that our biological neuron works. Biological neuron has three basic functionality Receive signal from outside.Process the signal and enhance whether we need to send information or
3 min read
What is Transposed Convolutional Layer?
A transposed convolutional layer is an upsampling layer that generates the output feature map greater than the input feature map. It is similar to a deconvolutional layer. A deconvolutional layer reverses the layer to a standard convolutional layer. If the output of the standard convolution layer is deconvolved with the deconvolutional layer then t
6 min read
FNet: A Transformer Without Attention Layer
This article delves into FNet, a transformative architecture that reimagines the traditional transformer by discarding attention mechanisms entirely. Let's begin the journey to explore FNet, but first, let's look at the limitations of transformers. What is FNet?In contrast to conventional transformer architectures, like the popular Transformer mode
7 min read
What is fractionally-strided convolution layer?
Answer: Fractionally-strided convolution (deconvolution) layer upsamples by inserting zeros between inputs and applying regular convolution.To understand fractionally-strided convolution, it's essential to first grasp the concept of regular (or "valid") convolution. In a standard convolution operation, a filter (also called a kernel) is applied to
2 min read
How to Decide the Window Size on a Pooling Layer?
Answer: The window size on a pooling layer is often determined based on the desired balance between feature preservation and spatial reduction in the input data.Determining the window size on a pooling layer involves considering several factors related to the specific task and characteristics of the input data. Pooling layers are commonly used in c
3 min read
What is a Neural Network Flatten Layer?
Answer: A neural network flatten layer is used to convert the multi-dimensional output from the previous layer into a one-dimensional array, typically before feeding it into a fully connected layer for further processing.A neural network flatten layer is a type of layer commonly used in deep learning architectures to transform multi-dimensional inp
2 min read