Sequence Models - Merged

Download as pdf or txt
Download as pdf or txt
You are on page 1of 67

Sequence Models

Sequence models are the machine learning models that input or output sequences of data.
Sequential data includes text streams, audio clips, video clips, time-series data and etc. Recurrent
Neural Networks (RNNs) is a popular algorithm used in sequence models.

Applications of Sequence Models


1. Speech recognition: In speech recognition, an audio clip is given as an input and then the model
has to generate its text transcript. Here both the input and output are sequences of data.

2. Sentiment Classification: In sentiment classification opinions expressed in a piece of text is


categorized. Here the input is a sequence of words.

1. Recurrent Neural Networks (RNNs)

 Description: RNNs are a type of neural network designed to recognize patterns in sequences
of data. They maintain a hidden state that captures information from previous time steps,
which is updated as new data points are processed sequentially.

 Key Components:

 Hidden State (h_t): Stores information from previous time steps.

 Input (x_t): The current data point in the sequence.

 Output (y_t): The predicted output at the current time step.

 Weights (W, U, V): Parameters that determine the transformation from inputs to
hidden states and outputs.

 Equation:

ℎ𝑡=𝜎(𝑊⋅𝑥𝑡+𝑈⋅ℎ𝑡−1)

𝑦𝑡=𝑉⋅ℎ𝑡

loss function

derivative of loss with respect to weight


RNN Architectures

There are several RNN architectures based on the number of inputs and outputs,
1. One to Many Architecture: Image captioning is one good example of this architecture. In image
captioning, it takes one image and then outputs a sequence of words. Here there is only one input
but many outputs.

2. Many to One Architecture: Sentiment classification is one good example of this architecture. In
sentiment classification, a given sentence is classified as positive or negative. In this case, the input is
a sequence of words and output is a binary classification.

3. Many to Many Architecture: There are two cases in many to many architectures,

 Applications: Useful for tasks where the sequence of data is important, such as time-series
forecasting, text generation, and speech recognition.
2. Long Short-Term Memory (LSTM)

 Description: LSTMs are a type of RNN that can learn long-term dependencies by using a
memory cell and three gates (input, forget, and output) to control the flow of information.

 Key Components:

 Cell State (C_t): Carries information across long sequences.

 Gates:

 Forget Gate (f_t): Decides what information to discard.

 Input Gate (i_t): Decides what new information to store.

 Output Gate (o_t): Decides what information to output.

 Equations:

𝑓𝑡=𝜎(𝑊𝑓⋅[ℎ𝑡−1,𝑥𝑡]+𝑏𝑓)

𝑖𝑡=𝜎(𝑊𝑖⋅[ℎ𝑡−1,𝑥𝑡]+𝑏𝑖)

𝐶𝑡~=tanh⁡(𝑊𝐶⋅[ℎ𝑡−1,𝑥𝑡]+𝑏𝐶)

𝐶𝑡=𝑓𝑡⋅𝐶𝑡−1+𝑖𝑡⋅𝐶𝑡~

𝑜𝑡=𝜎(𝑊𝑜⋅[ℎ𝑡−1,𝑥𝑡]+𝑏𝑜)

ℎ𝑡=𝑜𝑡⋅tanh⁡(𝐶𝑡)

LSTM is a very popular deep learning algorithm for sequence models. Apple’s Siri and Google’s voice
search are some real-world examples

 Applications: Particularly effective for tasks with long-term dependencies, like machine
translation, language modeling, and video processing.
3. Gated Recurrent Units (GRUs)

 Description: GRUs simplify LSTMs by combining the forget and input gates into a single
update gate, reducing the number of parameters.

 Take input the current input and the previous hidden state as vectors.

 For each gate, calculate the parameterized current input and previously hidden state vectors
by performing element-wise multiplication (Hadamard Product) between the concerned
vector and the respective weights for each gate.

 Apply the respective activation function for each gate element-wise on the parameterized
vectors. Below given is the list of the gates with the activation function to be applied for the
gate.

Key Components:

 Update Gate (z_t): Determines how much of the past information to carry forward.

 Reset Gate (r_t): Determines how to combine new input with the previous memory.

 Hidden state(TanH): candidate for hidden state

 Current Memory Gate( ht)

 Equations:

𝑧𝑡=𝜎(𝑊𝑧⋅[ℎ𝑡−1,𝑥𝑡])

𝑟𝑡=𝜎(𝑊𝑟⋅[ℎ𝑡−1,𝑥𝑡])

ℎ𝑡~=tanh⁡(𝑊⋅[𝑟𝑡⋅ℎ𝑡−1,𝑥𝑡])

ℎ𝑡=(1−𝑧𝑡)⋅ℎ𝑡−1+𝑧𝑡⋅ℎ𝑡~

Applications: Similar to LSTMs, used in natural language processing (NLP), speech recognition, and
time-series forecasting time-series forecasting.
Applications of Sequence Models

1. Natural Language Processing (NLP)

 Tasks:

 Language Modeling: Predicting the next word in a sequence to generate coherent


text.

 Text Summarization: Creating concise summaries of longer texts.

 Sentiment Analysis: Determining the sentiment expressed in a piece of text.

2. Language Models

 Description: Models that predict the probability of a sequence of words. Common examples
include GPT, BERT, and T5.

 Tasks: Autocomplete, machine translation, text generation.

3. Machine Translation

 Description: Translating text from one language to another using models like Seq2Seq with
attention mechanisms.

 Key Components:

 Encoder: Converts input text to a fixed-length context vector.

 Decoder: Generates translated text from the context vector.

4. Image Captioning

 Description: Generating descriptive text for images by combining convolutional neural


networks (CNNs) for feature extraction and RNNs/LSTMs for sequence generation.

 Key Components:

 CNN (e.g., VGG, ResNet): Extracts features from the image.

 RNN/LSTM: Generates a caption based on the extracted features.

5. Video Processing

 Description: Analyzing and generating video sequences. RNNs and LSTMs can be used to
capture temporal dependencies in video data.
 Tasks: Action recognition, video summarization, frame prediction.

6. Visual Question Answering (VQA)

 Description: Answering questions about images by combining visual (CNNs) and textual
(RNNs/LSTMs) data.

 Key Components:

 Image Feature Extraction (CNN): Extracts features from the image.

 Question Processing (RNN/LSTM): Processes the question to understand its context.

 Answer Generation: Combines visual and textual features to generate an answer.

7. Attention Mechanisms

 Description: Techniques that allow models to focus on relevant parts of the input sequence,
enhancing the ability to handle long-range dependencies.

 Key Components:

 Attention Weights: Determine the importance of different parts of the input.

 Self-Attention: Allows the model to consider all parts of the input when generating
outputs.

8. Attention Over Images

 Description: Applying attention mechanisms to image data, often used in image captioning
and VQA.

 Key Components:

 Spatial Attention: Focuses on different regions of an image.

 Temporal Attention: In video processing, focuses on different frames or parts of a


sequence.

These sequence models and their applications are essential in various fields, enabling the
development of sophisticated AI systems capable of understanding, generating, and interacting with
sequential data in diverse contexts.
What are Autoencoders?

Autoencoders are a specialized class of algorithms that can learn efficient representations of input
data with no need for labels. It is a class of artificial neural networks designed for unsupervised
learning. Learning to compress and effectively represent input data without specific labels is the
essential principle of an automatic decoder. This is accomplished using a two-fold structure that
consists of an encoder and a decoder. The encoder transforms the input data into a reduced-
dimensional representation, which is often referred to as “latent space” or “encoding”. From that
representation, a decoder rebuilds the initial input. For the network to gain meaningful patterns in
data, a process of encoding and decoding facilitates the definition of essential features.

Architecture of Autoencoder in Deep Learning

The general architecture of an autoencoder includes an encoder, decoder, and bottleneck layer.

1. Encoder

 Input layer take raw input data

 The hidden layers progressively reduce the dimensionality of the input, capturing
important features and patterns. These layer compose the encoder.

 The bottleneck layer (latent space) is the final hidden layer, where the
dimensionality is significantly reduced. This layer represents the compressed
encoding of the input data.
2. Decoder

 The bottleneck layer takes the encoded representation and expands it back to the
dimensionality of the original input.

 The hidden layers progressively increase the dimensionality and aim to reconstruct
the original input.

 The output layer produces the reconstructed output, which ideally should be as
close as possible to the input data.

3. The loss function used during training is typically a reconstruction loss, measuring the
difference between the input and the reconstructed output. Common choices include mean
squared error (MSE) for continuous data or binary cross-entropy for binary data.

4. During training, the autoencoder learns to minimize the reconstruction loss, forcing the
network to capture the most important features of the input data in the bottleneck layer.

After the training process, only the encoder part of the autoencoder is retained to encode a similar
type of data used in the training process. The different ways to constrain the network are: –

 Keep small Hidden Layers: If the size of each hidden layer is kept as small as possible, then
the network will be forced to pick up only the representative features of the data thus
encoding the data.

 Regularization: In this method, a loss term is added to the cost function which encourages
the network to train in ways other than copying the input.

 Denoising: Another way of constraining the network is to add noise to the input and teach
the network how to remove the noise from the data.

 Tuning the Activation Functions: This method involves changing the activation functions of
various nodes so that a majority of the nodes are dormant thus, effectively reducing the size
of the hidden layers.
Types of Autoencoders

There are diverse types of autoencoders and analyze the advantages and disadvantages associated
with different variation:

Denoising Autoencoder

Denoising autoencoder works on a partially corrupted input and trains to recover the original
undistorted image. As mentioned above, this method is an effective way to constrain the network
from simply copying the input and thus learn the underlying structure and important features of the
data.

Advantages

1. This type of autoencoder can extract important features and reduce the noise or the useless
features.

2. Denoising autoencoders can be used as a form of data augmentation, the restored images
can be used as augmented data thus generating additional training samples.

Disadvantages

1. Selecting the right type and level of noise to introduce can be challenging and may require
domain knowledge.

2. Denoising process can result into loss of some information that is needed from the original
input. This loss can impact accuracy of the output.

Sparse Autoencoder

This type of autoencoder typically contains more hidden units than the input but only a few are
allowed to be active at once. This property is called the sparsity of the network. The sparsity of the
network can be controlled by either manually zeroing the required hidden units, tuning the
activation functions or by adding a loss term to the cost function.

Advantages

1. The sparsity constraint in sparse autoencoders helps in filtering out noise and irrelevant
features during the encoding process.

2. These autoencoders often learn important and meaningful features due to their emphasis
on sparse activations.

Disadvantages

1. The choice of hyperparameters play a significant role in the performance of this


autoencoder. Different inputs should result in the activation of different nodes of the
network.

2. The application of sparsity constraint increases computational complexity.


Variational Autoencoder

Variational autoencoder makes strong assumptions about the distribution of latent variables and
uses the Stochastic Gradient Variational Bayes estimator in the training process. It assumes that the
data is generated by a Directed Graphical Model and tries to learn an approximation to are the
parameters of the encoder and the decoder respectively.

Advantages

1. Variational Autoencoders are used to generate new data points that resemble the original
training data. These samples are learned from the latent space.

2. Variational Autoencoder is probabilistic framework that is used to learn a compressed


representation of the data that captures its underlying structure and variations, so it is
useful in detecting anomalies and data exploration.

Disadvantages

1. Variational Autoencoder use approximations to estimate the true distribution of the latent
variables. This approximation introduces some level of error, which can affect the quality of
generated samples.

2. The generated samples may only cover a limited subset of the true data distribution. This
can result in a lack of diversity in generated samples.

Convolutional Autoencoder

Convolutional autoencoders are a type of autoencoder that use convolutional neural networks
(CNNs) as their building blocks. The encoder consists of multiple layers that take a image or a grid as
input and pass it through different convolution layers thus forming a compressed representation of
the input. The decoder is the mirror image of the encoder it deconvolves the compressed
representation and tries to reconstruct the original image.

Advantages

1. Convolutional autoencoder can compress high-dimensional image data into a lower-


dimensional data. This improves storage efficiency and transmission of image data.

2. Convolutional autoencoder can reconstruct missing parts of an image. It can also handle
images with slight variations in object position or orientation.

Disadvantages

1. These autoencoder are prone to overfitting. Proper regularization techniques should be


used to tackle this issue.

2. Compression of data can cause data loss which can result in reconstruction of a lower quality
image.
What is Batch Normalization?

Batch normalization is a deep learning approach that has been shown to significantly improve the
efficiency and reliability of neural network models. It is particularly useful for training very deep
networks, as it can help to reduce the internal covariate shift that can occur during training.

 Batch normalization is a supervised learning method for normalizing the interlayer outputs
of a neural network. As a result, the next layer receives a “reset” of the output distribution
from the preceding layer, allowing it to analyze the data more effectively.

Batch normalization is a technique used to improve the performance of a deep learning network by
first removing the batch mean and then splitting it by the batch standard deviation.

Stochastic gradient descent is used to rectify this standardization if the loss function is too big, by
shifting or scaling the outputs by a parameter, which in turn affects the accuracy of the weights in
the following layer.

When applied to a layer, batch normalization multiplies its output by a standard deviation parameter
(gamma) and adds a mean parameter (beta) to it as a secondary trainable parameter. Data may be
“denormalized” by adjusting just these two weights for each output, thanks to the synergy between
batch normalization and gradient descents. Reduced data loss and improved network stability were
the results of adjusting the other relevant weights.

The goal of batch normalization is to stabilize the training process and improve the generalization
ability of the model.

1. Image Classification

 Application: Batch normalization is extensively used in Convolutional Neural Networks


(CNNs) for tasks like image classification, object detection, and segmentation.

 Type: Standard batch normalization is applied after convolutional layers and before
activation functions.

2. Natural Language Processing (NLP)

 Application: Batch normalization can be beneficial in recurrent neural networks (RNNs) and
transformer-based models for tasks like language translation, text generation, and
sentiment analysis.

 Type: Layer normalization is often preferred over batch normalization due to the sequential
nature of text data.
Regularization is a technique used in machine learning and deep learning to prevent overfitting and
improve the generalization ability of models. It involves adding a penalty term to the loss function,
which discourages complex models that might fit the training data too closely. Here are the types of
regularization commonly used:

1. L2 Regularization (Ridge Regression)

 Description: Also known as weight decay, L2 regularization adds a penalty term proportional
to the square of the magnitude of weights to the loss function.

 Formula: Lossregularized=Lossoriginal+𝜆2∑𝑖=1𝑛𝑤𝑖2Lossregularized=Lossoriginal+2λ∑i=1nwi2

 Effect: Encourages smaller weights across all features, preventing any single feature from
dominating the model.

2. L1 Regularization (Lasso Regression)

 Description: L1 regularization adds a penalty term proportional to the absolute value of


weights to the loss function.

 Formula: Lossregularized=Lossoriginal+𝜆∑𝑖=1𝑛∣𝑤𝑖∣Lossregularized=Lossoriginal+λ∑i=1n∣wi∣

 Effect: Encourages sparsity in feature weights, effectively performing feature selection by


pushing some weights to zero.

3. Elastic Net Regularization

 Description: Elastic Net regularization combines L1 and L2 regularization, adding both


penalties to the loss function.

 Formula: Lossregularized=Lossoriginal+𝜆1∑𝑖=1𝑛∣𝑤𝑖∣+𝜆22∑𝑖=1𝑛𝑤𝑖2Lossregularized
=Lossoriginal+λ1∑i=1n∣wi∣+2λ2∑i=1nwi2

 Effect: Balances between L1 and L2 regularization, providing a compromise between feature


selection and coefficient shrinkage.

4. Dropout

 Description: Dropout is a regularization technique specific to neural networks. During


training, randomly selected neurons are temporarily dropped out (i.e., set to zero) along
with their connections with a certain probability.

 Effect: Forces the network to learn redundant representations, reducing co-adaptation of


neurons and preventing overfitting.

5. Early Stopping

 Description: Early stopping is a simple form of regularization where training is stopped when
the performance on a validation set starts to degrade.

 Effect: Prevents the model from overfitting by halting training before it becomes too
specialized to the training data.

Regularization techniques can be used individually or in combination to effectively control


overfitting and improve the performance of machine learning and deep learning models. Each
technique has its advantages and is suited to different scenarios and types of data.
CNN architecture

 Input Layers: It’s the layer in which we give input to our model. In CNN, Generally, the input
will be an image or a sequence of images. This layer holds the raw input of the image with
width 32, height 32, and depth 3.

 Convolutional Layers: This is the layer, which is used to extract the feature from the input
dataset. It applies a set of learnable filters known as the kernels to the input images. The
filters/kernels are smaller matrices usually 2×2, 3×3, or 5×5 shape. it slides over the input
image data and computes the dot product between kernel weight and the corresponding
input image patch. The output of this layer is referred as feature maps. Suppose we use a
total of 12 filters for this layer we’ll get an output volume of dimension 32 x 32 x 12.

 Activation Layer: By adding an activation function to the output of the preceding layer,
activation layers add nonlinearity to the network. it will apply an element-wise activation
function to the output of the convolution layer. Some common activation functions
are RELU: max(0, x), Tanh, Leaky RELU, etc. The volume remains unchanged hence output
volume will have dimensions 32 x 32 x 12.

 Pooling layer: This layer is periodically inserted in the covnets and its main function is to
reduce the size of volume which makes the computation fast reduces memory and also
prevents overfitting. Two common types of pooling layers are max pooling and average
pooling. If we use a max pool with 2 x 2 filters and stride 2, the resultant volume will be of
dimension 16x16x12.

 Flattening: The resulting feature maps are flattened into a one-dimensional vector after the
convolution and pooling layers so they can be passed into a completely linked layer for
categorization or regression.

 Fully Connected Layers: It takes the input from the previous layer and computes the final
classification or regression task.

 Output Layer: The output from the fully connected layers is then fed into a logistic function
for classification tasks like sigmoid or softmax which converts the output of each class into
the probability score of each class
Advantages of Convolutional Neural Networks (CNNs):

1. Good at detecting patterns and features in images, videos, and audio signals.

2. Robust to translation, rotation, and scaling invariance.

3. End-to-end training, no need for manual feature extraction.

4. Can handle large amounts of data and achieve high accuracy.

Disadvantages of Convolutional Neural Networks (CNNs):

1. Computationally expensive to train and require a lot of memory.

2. Can be prone to overfitting if not enough data or proper regularization is used.

3. Requires large amounts of labeled data.

4. Interpretability is limited, it’s hard to understand what the network has learned.

1: What is a Convolutional Neural Network (CNN)?

A Convolutional Neural Network (CNN) is a type of deep learning neural network that is well-suited
for image and video analysis. CNNs use a series of convolution and pooling layers to extract features
from images and videos, and then use these features to classify or detect objects or scenes.
Convolutional Neural Network (CNN) in Machine Learning

Convolutional Neural Networks (CNNs) are a powerful tool for machine learning, especially in tasks
related to computer vision. Convolutional Neural Networks, or CNNs, are a specialized class of neural
networks designed to effectively process grid-like data, such as images.

In this article, we are going to discuss convolutional neural networks (CNN) in machine learning in
detail.

What is Convolutional Neural Network(CNN)?

A Convolutional Neural Network (CNN) is a type of deep learning algorithm that is particularly well-
suited for image recognition and processing tasks. It is made up of multiple layers, including
convolutional layers, pooling layers, and fully connected layers. The architecture of CNNs is inspired
by the visual processing in the human brain, and they are well-suited for capturing hierarchical
patterns and spatial dependencies within images.

Key components of a Convolutional Neural Network include:

1. Convolutional Layers: These layers apply convolutional operations to input images, using
filters (also known as kernels) to detect features such as edges, textures, and more complex
patterns. Convolutional operations help preserve the spatial relationships between pixels.

2. Pooling Layers: Pooling layers downsample the spatial dimensions of the input, reducing the
computational complexity and the number of parameters in the network. Max pooling is a
common pooling operation, selecting the maximum value from a group of neighboring pixels.

3. Activation Functions: Non-linear activation functions, such as Rectified Linear Unit (ReLU),
introduce non-linearity to the model, allowing it to learn more complex relationships in the
data.

4. Fully Connected Layers: These layers are responsible for making predictions based on the
high-level features learned by the previous layers. They connect every neuron in one layer to
every neuron in the next layer.

Convolutional Neural Network Design

 The construction of a convolutional neural network is a multi-layered feed-forward neural


network, made by assembling many unseen layers on top of each other in a particular order.

 It is the sequential design that give permission to CNN to learn hierarchical attributes.

 In CNN, some of them followed by grouping layers and hidden layers are typically
convolutional layers followed by activation layers.

 The pre-processing needed in a ConvNet is kindred to that of the related pattern of neurons
in the human brain and was motivated by the organization of the Visual Cortex.

Convolutional Neural Network Training

CNNs are trained using a supervised learning approach. This means that the CNN is given a set of
labeled training images. The CNN then learns to map the input images to their correct labels.

The training process for a CNN involves the following steps:


1. Data Preparation: The training images are preprocessed to ensure that they are all in the
same format and size.

2. Loss Function: A loss function is used to measure how well the CNN is performing on the
training data. The loss function is typically calculated by taking the difference between the
predicted labels and the actual labels of the training images.

3. Optimizer: An optimizer is used to update the weights of the CNN in order to minimize the
loss function.

4. Backpropagation: Backpropagation is a technique used to calculate the gradients of the loss


function with respect to the weights of the CNN. The gradients are then used to update the
weights of the CNN using the optimizer.

CNN Evaluation

After training, CNN can be evaluated on a held-out test set. A collection of pictures that the CNN has
not seen during training makes up the test set. How well the CNN performs on the test set is a good
predictor of how well it will function on actual data.

The efficiency of a CNN on picture categorization tasks can be evaluated using a variety of criteria.
Among the most popular metrics are:

 Accuracy: Accuracy is the percentage of test images that the CNN correctly classifies.

 Precision: Precision is the percentage of test images that the CNN predicts as a particular
class and that are actually of that class.

 Recall: Recall is the percentage of test images that are of a particular class and that the CNN
predicts as that class.

 F1 Score: The F1 Score is a harmonic mean of precision and recall. It is a good metric for
evaluating the performance of a CNN on classes that are imbalanced.

Different Types of CNN Models

1. LeNet

2. AlexNet

3. ResNet

4. GoogleNet

5. MobileNet

6. VGG
1.LeNet

 The First LeNet-5 architecture is the most widely known CNN architecture. It was
introduced in 1998 and is widely used for handwritten method digit recognition.

 LeNet-5 has 2 convolutional and 3 full layers.

 This LeNet-5 architecture has 60,000 parameters.

 The LeNet-5 has the ability to process higher one-resolution images that require larger and
more CNN convolutional layers.

 The leNet-5 technique is measured by the availability of all computing resources


2.AlexNet

 AlexNet is a convolutional neural network (CNN) architecture that was developed by Alex
Krizhevsky, Ilya Sutskever, and Geoffrey Hinton in 2012. It was the first CNN to win the
ImageNet Large Scale Visual Recognition Challenge (ILSVRC), a major image recognition
competition, and it helped to establish CNNs as a powerful tool for image recognition.

 AlexNet consists of several layers of convolutional and pooling layers, followed by fully
connected layers. The architecture includes five convolutional layers, three pooling layers,
and three fully connected layers.

 The first two convolutional layers use a kernel of size 11×11 and apply 96 filters to the input
image. The third and fourth convolutional layers use a kernel of size 5×5 and apply 256
filters. The fifth convolutional layer uses a kernel of size 3×3 and applies 384 filters. The
output of these convolutional layers is then passed through max-pooling layers that reduce
the spatial dimensions of the feature maps.

 The output of the pooling layers is then passed through three fully connected layers, with
4096, 4096, and 1000 neurons respectively. The last fully connected layer is used for
classification, and produces a probability distribution over the 1000 ImageNet classes.

 AlexNet was trained on the ImageNet dataset, which consists of 1.2 million images with 1000
classes, and was able to achieve high recognition accuracy.
3. Resnet

 ResNets (Residual Networks) are a type of deep learning algorithm that are particularly well-
suited for image recognition and processing tasks. ResNets are known for their ability to train
very deep networks without overfitting

 ResNets are often used for keypoint detection tasks. Keypoint detection is the task of locating
specific points on an object in an image. For example, keypoint detection can be used to
locate the eyes, nose, and mouth on a human face.

 ResNets are well-suited for keypoint detection tasks because they can learn to extract
features from images at different scales.

 ResNets have achieved state-of-the-art results on many keypoint detection benchmarks, such
as the COCO Keypoint Detection Challenge and the MPII Human Pose Estimation Dataset.
4.GoogleNet

 GoogleNet, also known as InceptionNet, is a type of deep learning algorithm that is


particularly well-suited for image recognition and processing tasks. GoogleNet is known for
its ability to achieve high accuracy on image classification tasks while using fewer
parameters and computational resources than other state-of-the-art CNNs.

 Inception modules are the key component of GoogleNet. They allow the network to learn
features at different scales simultaneously, which improves the performance of the network
on image classification tasks.

 GoogleNet uses global average pooling to reduce the size of the feature maps before they
are passed to the fully connected layers. This also helps to improve the performance of the
network on image classification tasks.

 GoogleNet uses factorized convolutions to reduce the number of parameters and


computational resources required to train the network.

 GoogleNet is a powerful tool for image classification, and it is being used in a wide variety of
applications, such as GoogleNet can be used to classify images into different categories, such
as cats and dogs, cars and trucks, and flowers and animals


6. VGG

 VGG is a type of convolutional neural network (CNN) that is known for its simplicity and
effectiveness. VGGs are typically made up of a series of convolutional and pooling layers,
followed by a few fully connected layers.

 VGGs can be used by self-driving cars to detect and classify objects on the road, such as other
vehicles, pedestrians, and traffic signs. This information can be used to help the car navigate
safely.

 VGGs are a powerful and versatile tool for image recognition tasks.
ZFNet architecture:

5 Convolutional layers.

3 Fully connected layers.

3 Overlapping Max pooling layers.

ReLU as activation function for hidden layer.

Softmax as activation function for output layer.

60,000,000 trainable parameters.

Cross-entropy as cost function

Mini-batch gradient descent with Momentum optimizer.

Local Response Normalization (Removing it seems to give better results)


Applications of CNN

 Image classification: CNNs are the state-of-the-art models for image classification. They can
be used to classify images into different categories, such as cats and dogs, cars and
trucks, and flowers and animals.

 Object detection: CNNs can be used to detect objects in images, such as people, cars, and
buildings. They can also be used to localize objects in images, which means that they can
identify the location of an object in an image.

 Image segmentation: CNNs can be used to segment images, which means that they can
identify and label different objects in an image. This is useful for applications such as medical
imaging and robotics.

 Video analysis: CNNs can be used to analyze videos, such as tracking objects in a video or
detecting events in a video. This is useful for applications such as video surveillance and
traffic monitoring.

Advantages of CNN

 CNNs can achieve state-of-the-art accuracy on a variety of image recognition tasks, such as
image classification, object detection, and image segmentation.

 CNNs can be very efficient, especially when implemented on specialized hardware such as
GPUs.

 CNNs are relatively robust to noise and variations in the input data.

 CNNs can be adapted to a variety of different tasks by simply changing the architecture of
the network.

Disadvantages of CNN

 CNNs can be complex and difficult to train, especially for large datasets.

 CNNs can require a lot of computational resources to train and deploy.

 CNNs require a large amount of labeled data to train.

 CNNs can be difficult to interpret, making it difficult to understand why they make the
predictions they do.
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

CoursesTutorialsJobsPracticeContests

Generative Adversarial Network (GAN)


Last Updated : 11 Mar, 2024
GAN(Generative Adversarial Network) represents a cutting-edge approach
to generative modeling within deep learning, often leveraging architectures
like convolutional neural networks. The goal of generative modeling is to
autonomously identify patterns in input data, enabling the model to produce
new examples that feasibly resemble the original dataset.

This article covers everything you need to know about GAN, the
Architecture of GAN, the Workings of GAN, and types of GAN Models,
and so on.

Table of Content
What is a Generative Adversarial Network?
Types of GANs
Architecture of GANs
How does a GAN work?
Implementation of a GAN
Application Of Generative Adversarial Networks (GANs)
Advantages of GAN
Disadvantages of GAN
GAN(Generative Adversarial Network)- FAQs

What is a Generative Adversarial Network?


Generative Adversarial Networks (GANs) are a powerful class of neural
networks that are used for an unsupervised learning. GANs are made up of
two neural networks, a discriminator and a generator. They use adversarial
training to produce artificial data that is identical to actual data.

The Generator attempts to fool the Discriminator, which is tasked with


accurately distinguishing between produced and genuine data, by
producing random noise samples.
Realistic, high-quality samples are produced as a result of this
competitive interaction, which drives both networks toward advancement.

https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 1/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

GANs are proving to be highly versatile artificial intelligence tools, as


evidenced by their extensive use in image synthesis, style transfer, and
text-to-image synthesis.
They have also revolutionized generative modeling.

Through adversarial training, these models engage in a competitive interplay


until the generator becomes adept at creating realistic samples, fooling the
discriminator approximately half the time.

Generative Adversarial Networks (GANs) can be broken down into three


parts:

Generative: To learn a generative model, which describes how data is


generated in terms of a probabilistic model.
Adversarial: The word adversarial refers to setting one thing up against
another. This means that, in the context of GANs, the generative result is
compared with the actual images in the data set. A mechanism known as
a discriminator is used to apply a model that attempts to distinguish
between real and fake images.

https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 2/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

Networks: Use deep neural networks as artificial intelligence (AI)


algorithms for training purposes.

Types of GANs
1. Vanilla GAN: This is the simplest type of GAN. Here, the Generator and
the Discriminator are simple a basic multi-layer perceptrons. In vanilla
GAN, the algorithm is really simple, it tries to optimize the mathematical
equation using stochastic gradient descent.
2. Conditional GAN (CGAN): CGAN can be described as a deep learning
method in which some conditional parameters are put into place.
In CGAN, an additional parameter ‘y’ is added to the Generator for
generating the corresponding data.
Labels are also put into the input to the Discriminator in order for the
Discriminator to help distinguish the real data from the fake generated
data.

3. Deep Convolutional GAN (DCGAN): DCGAN is one of the most popular


and also the most successful implementations of GAN. It is composed of
ConvNets in place of multi-layer perceptrons.
The ConvNets are implemented without max pooling, which is in fact
replaced by convolutional stride.
Also, the layers are not fully connected.

4. Laplacian Pyramid GAN (LAPGAN): The Laplacian pyramid is a linear


invertible image representation consisting of a set of band-pass images,
spaced an octave apart, plus a low-frequency residual.
This approach uses multiple numbers of Generator and
Discriminator networks and different levels of the Laplacian Pyramid.
This approach is mainly used because it produces very high-quality
images. The image is down-sampled at first at each layer of the
pyramid and then it is again up-scaled at each layer in a backward
pass where the image acquires some noise from the Conditional GAN
at these layers until it reaches its original size.

5. Super Resolution GAN (SRGAN): SRGAN as the name suggests is a way


of designing a GAN in which a deep neural network is used along with an
adversarial network in order to produce higher-resolution images. This
type of GAN is particularly useful in optimally up-scaling native low-

https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 3/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

resolution images to enhance their details minimizing errors while doing


so.

Architecture of GANs
A Generative Adversarial Network (GAN) is composed of two primary parts,
which are the Generator and the Discriminator.

Generator Model

A key element responsible for creating fresh, accurate data in a Generative


Adversarial Network (GAN) is the generator model. The generator takes
random noise as input and converts it into complex data samples, such text
or images. It is commonly depicted as a deep neural network.

The training data’s underlying distribution is captured by layers of learnable


parameters in its design through training. The generator adjusts its output to
produce samples that closely mimic real data as it is being trained by using
backpropagation to fine-tune its parameters.

The generator’s ability to generate high-quality, varied samples that can fool
the discriminator is what makes it successful.
Generator Loss
The objective of the generator in a GAN is to produce synthetic samples that
are realistic enough to fool the discriminator. The generator achieves this by
minimizing its loss function JG ​. The loss is minimized when the log

probability is maximized, i.e., when the discriminator is highly likely to


classify the generated samples as real. The following equation is given
below:

JG = − m1 Σm

i=1 logD(G(zi ))
​ ​ ​

Where,

JG measure how well the generator is fooling the discriminator.


log D(G(zi ))represents log probability of the discriminator being correct


for generated samples.


The generator aims to minimize this loss, encouraging the production of
samples that the discriminator classifies as real (logD(G(zi )), close to 1. ​

Discriminator Model

https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 4/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

An artificial neural network called a discriminator model is used in


Generative Adversarial Networks (GANs) to differentiate between generated
and actual input. By evaluating input samples and allocating probability of
authenticity, the discriminator functions as a binary classifier.

Over time, the discriminator learns to differentiate between genuine data


from the dataset and artificial samples created by the generator. This allows
it to progressively hone its parameters and increase its level of proficiency.

Convolutional layers or pertinent structures for other modalities are usually


used in its architecture when dealing with picture data. Maximizing the
discriminator’s capacity to accurately identify generated samples as
fraudulent and real samples as authentic is the aim of the adversarial
training procedure. The discriminator grows increasingly discriminating as a
result of the generator and discriminator’s interaction, which helps the GAN
produce extremely realistic-looking synthetic data overall.
Discriminator Loss
The discriminator reduces the negative log likelihood of correctly classifying
both produced and real samples. This loss incentivizes the discriminator to
accurately categorize generated samples as fake and real samples with the
Trending Now DSA
following Web Tech Foundational Courses Data Science Practice Problem Python Machin
equation:
JD = − m1 Σm
​ ​
1 m
i=1 l og D(xi )– m Σi=1 l og(1–D(G(zi ))
​ ​ ​ ​ ​

JD assesses the discriminator’s ability to discern between produced and


actual samples.
The log likelihood that the discriminator will accurately categorize real
data is represented by logD(xi ). ​

The log chance that the discriminator would correctly categorize


generated samples as fake is represented by log⁡(1 − D(G(zi ))). ​

The discriminator aims to reduce this loss by accurately identifying


artificial and real samples.

MinMax Loss
In a Generative Adversarial Network (GAN), the minimax loss formula is
provided by:

minG maxD (G, D) = [Ex∼pdata [log D(x)] + Ez∼pz (z) [log(1–D(g(z)))]


​ ​



Where,

G is generator network and is D is the discriminator network

https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 5/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

Actual data samples obtained from the true data distribution pdata (x) are ​

represented by x.
Random noise sampled from a previous distribution pz (z)(usually a normal ​

or uniform distribution) is represented by z.


D(x) represents the discriminator’s likelihood of correctly identifying
actual data as real.
D(G(z)) is the likelihood that the discriminator will identify generated data
coming from the generator as authentic.

How does a GAN work?


The steps involved in how a GAN works:

1. Initialization: Two neural networks are created: a Generator (G) and a


Discriminator (D).
G is tasked with creating new data, like images or text, that closely
resembles real data.
D acts as a critic, trying to distinguish between real data (from a
training dataset) and the data generated by G.

2. Generator’s First Move: G takes a random noise vector as input. This


noise vector contains random values and acts as the starting point for G’s
creation process. Using its internal layers and learned patterns, G
transforms the noise vector into a new data sample, like a generated
image.
3. Discriminator’s Turn: D receives two kinds of inputs:
Real data samples from the training dataset.
The data samples generated by G in the previous step. D’s job is to
analyze each input and determine whether it’s real data or something
https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 6/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

G cooked up. It outputs a probability score between 0 and 1. A score of


1 indicates the data is likely real, and 0 suggests it’s fake.
4. The Learning Process: Now, the adversarial part comes in:
If D correctly identifies real data as real (score close to 1) and
generated data as fake (score close to 0), both G and D are rewarded
to a small degree. This is because they’re both doing their jobs well.
However, the key is to continuously improve. If D consistently identifies
everything correctly, it won’t learn much. So, the goal is for G to
eventually trick D.

5. Generator’s Improvement:
When D mistakenly labels G’s creation as real (score close to 1), it’s a
sign that G is on the right track. In this case, G receives a significant
positive update, while D receives a penalty for being fooled.
This feedback helps G improve its generation process to create more
realistic data.

6. Discriminator’s Adaptation:
Conversely, if D correctly identifies G’s fake data (score close to 0), but
G receives no reward, D is further strengthened in its discrimination
abilities.
This ongoing duel between G and D refines both networks over time.

As training progresses, G gets better at generating realistic data, making it


harder for D to tell the difference. Ideally, G becomes so adept that D can’t
reliably distinguish real from fake data. At this point, G is considered well-
trained and can be used to generate new, realistic data samples.

Implementation of Generative Adversarial Network


(GAN)
We will follow and understand the steps to understand how GAN is
implemented:
Step1 : Importing the required libraries

Python3

import torch
import torch.nn as nn
import torch.optim as optim
import torchvision
https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 7/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

from torchvision import datasets, transforms


import matplotlib.pyplot as plt
import numpy as np

# Set device
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

For training on the CIFAR-10 image dataset, this PyTorch module creates a
Generative Adversarial Network (GAN), switching between generator and
discriminator training. Visualization of the generated images occurs every
tenth epoch, and the development of the GAN is tracked.
Step 2: Defining a Transform
The code uses PyTorch’s transforms to define a simple picture
transforms.Compose. It normalizes and transforms photos into tensors.

Python3

# Define a basic transform


transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])

Step 3: Loading the Dataset


A CIFAR-10 dataset is created for training with below code, which also
specifies a root directory, turns on train mode, downloads if needed, and
applies the specified transform. Subsequently, it generates a 32-batch
DataLoader and shuffles the training set of data.

Python3

train_dataset = datasets.CIFAR10(root='./data',\
train=True, download=True, transform=transform)
dataloader = torch.utils.data.DataLoader(train_dataset, \
batch_size=32, shuffle=True)

Step 4: Defining parameters to be used in later processes

https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 8/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

A Generative Adversarial Network (GAN) is used with specified


hyperparameters.

The latent space’s dimensionality is represented by latent_dim.


lr is the optimizer’s learning rate.
The coefficients for the Adam optimizer are beta1 and beta2. To find the
total number of training epochs, use num_epochs.

Python3

# Hyperparameters
latent_dim = 100
lr = 0.0002
beta1 = 0.5
beta2 = 0.999
num_epochs = 10

Step 5: Defining a Utility Class to Build the Generator


The generator architecture for a GAN in PyTorch is defined with below code.

From nn.Module, the Generator class inherits. It is comprised of a


sequential model with Tanh, linear, convolutional, batch normalization,
reshaping, and upsampling layers.
The neural network synthesizes an image (img) from a latent vector (z),
which is the generator’s output.

The architecture uses a series of learned transformations to turn the initial


random noise in the latent space into a meaningful image.

Python3

# Define the generator


class Generator(nn.Module):
def __init__(self, latent_dim):
super(Generator, self).__init__()

self.model = nn.Sequential(
nn.Linear(latent_dim, 128 * 8 * 8),
nn.ReLU(),
nn.Unflatten(1, (128, 8, 8)),
nn.Upsample(scale_factor=2),
nn.Conv2d(128, 128, kernel_size=3, padding=1),
nn.BatchNorm2d(128, momentum=0.78),
https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 9/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

nn.ReLU(),
nn.Upsample(scale_factor=2),
nn.Conv2d(128, 64, kernel_size=3, padding=1),
nn.BatchNorm2d(64, momentum=0.78),
nn.ReLU(),
nn.Conv2d(64, 3, kernel_size=3, padding=1),
nn.Tanh()
)

def forward(self, z):


img = self.model(z)
return img

Step 6: Defining a Utility Class to Build the Discriminator


The PyTorch code describes the discriminator architecture for a GAN. The
class Discriminator is descended from nn.Module. It is composed of linear
layers, batch normalization, dropout, convolutional, LeakyReLU, and
sequential layers.

An image (img) is the discriminator’s input, and its validity—the probability


that the input image is real as opposed to artificial—is its output.

Python3

# Define the discriminator


class Discriminator(nn.Module):
def __init__(self):
super(Discriminator, self).__init__()

self.model = nn.Sequential(
nn.Conv2d(3, 32, kernel_size=3, stride=2, padding=1),
nn.LeakyReLU(0.2),
nn.Dropout(0.25),
nn.Conv2d(32, 64, kernel_size=3, stride=2, padding=1),
nn.ZeroPad2d((0, 1, 0, 1)),
nn.BatchNorm2d(64, momentum=0.82),
nn.LeakyReLU(0.25),
nn.Dropout(0.25),
nn.Conv2d(64, 128, kernel_size=3, stride=2, padding=1),
nn.BatchNorm2d(128, momentum=0.82),
nn.LeakyReLU(0.2),
nn.Dropout(0.25),
nn.Conv2d(128, 256, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(256, momentum=0.8),
nn.LeakyReLU(0.25),
nn.Dropout(0.25),
nn.Flatten(),

https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 10/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

nn.Linear(256 * 5 * 5, 1),
nn.Sigmoid()
)

def forward(self, img):


validity = self.model(img)
return validity

Step 7: Building the Generative Adversarial Network


The code snippet defines and initializes a discriminator (Discriminator) and a
generator (Generator).

The designated device (GPU if available) receives both models. Binary


Cross Entropy Loss, which is frequently used for GANs, is selected as the
loss function (adversarial_loss).
For the generator (optimizer_G) and discriminator (optimizer_D), distinct
Adam optimizers with predetermined learning rates and betas are also
defined.

Python3

# Define the generator and discriminator


# Initialize generator and discriminator
generator = Generator(latent_dim).to(device)
discriminator = Discriminator().to(device)
# Loss function
adversarial_loss = nn.BCELoss()
# Optimizers
optimizer_G = optim.Adam(generator.parameters()\
, lr=lr, betas=(beta1, beta2))
optimizer_D = optim.Adam(discriminator.parameters()\
, lr=lr, betas=(beta1, beta2))

Step 8: Training the Generative Adversarial Network


For a Generative Adversarial Network (GAN), the code implements the
training loop.

The training data batches are iterated through during each epoch.
Whereas the generator (optimizer_G) is trained to generate realistic
images that trick the discriminator, the discriminator (optimizer_D) is
trained to distinguish between real and phony images.

https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 11/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

The generator and discriminator’s adversarial losses are computed. Model


parameters are updated by means of Adam optimizers and the losses are
backpropagated.
Discriminator printing and generator losses are used to track progress.
For a visual assessment of the training process, generated images are
additionally saved and shown every 10 epochs.

Python3

# Training loop
for epoch in range(num_epochs):
for i, batch in enumerate(dataloader):
# Convert list to tensor
real_images = batch[0].to(device)
# Adversarial ground truths
valid = torch.ones(real_images.size(0), 1, device=device)
fake = torch.zeros(real_images.size(0), 1, device=device)
# Configure input
real_images = real_images.to(device)

# ---------------------
# Train Discriminator
# ---------------------
optimizer_D.zero_grad()
# Sample noise as generator input
z = torch.randn(real_images.size(0), latent_dim, device=device)
# Generate a batch of images
fake_images = generator(z)

# Measure discriminator's ability


# to classify real and fake images
real_loss = adversarial_loss(discriminator\
(real_images), valid)
fake_loss = adversarial_loss(discriminator\
(fake_images.detach()), fake)
d_loss = (real_loss + fake_loss) / 2
# Backward pass and optimize
d_loss.backward()
optimizer_D.step()

# -----------------
# Train Generator
# -----------------

optimizer_G.zero_grad()
# Generate a batch of images
gen_images = generator(z)
# Adversarial loss
g_loss = adversarial_loss(discriminator(gen_images), valid)

https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 12/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

# Backward pass and optimize


g_loss.backward()
optimizer_G.step()
# ---------------------
# Progress Monitoring
# ---------------------
if (i + 1) % 100 == 0:
print(
f"Epoch [{epoch+1}/{num_epochs}]\
Batch {i+1}/{len(dataloader)} "
f"Discriminator Loss: {d_loss.item():.4f} "
f"Generator Loss: {g_loss.item():.4f}"
)
# Save generated images for every epoch
if (epoch + 1) % 10 == 0:
with torch.no_grad():
z = torch.randn(16, latent_dim, device=device)
generated = generator(z).detach().cpu()
grid = torchvision.utils.make_grid(generated,\
nrow=4, normalize=True)
plt.imshow(np.transpose(grid, (1, 2, 0)))
plt.axis("off")
plt.show()

Output:

Epoch [10/10] Batch 1300/1563 Discriminator


Loss: 0.4473 Generator Loss: 0.9555
Epoch [10/10] Batch 1400/1563 Discriminator
Loss: 0.6643 Generator Loss: 1.0215
Epoch [10/10] Batch 1500/1563 Discriminator
Loss: 0.4720 Generator Loss: 2.5027

https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 13/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

GAN Output

Application Of Generative Adversarial Networks (GANs)


GANs, or Generative Adversarial Networks, have many uses in many
different fields. Here are some of the widely recognized uses of GANs:

1. Image Synthesis and Generation : GANs are often used for picture
synthesis and generation tasks, They may create fresh, lifelike pictures
that mimic training data by learning the distribution that explains the
dataset. The development of lifelike avatars, high-resolution
photographs, and fresh artwork have all been facilitated by these types of
generative networks.
2. Image-to-Image Translation : GANs may be used for problems involving
image-to-image translation, where the objective is to convert an input
picture from one domain to another while maintaining its key features.
GANs may be used, for instance, to change pictures from day to night,
transform drawings into realistic images, or change the creative style of
an image.
3. Text-to-Image Synthesis : GANs have been used to create visuals from
descriptions in text. GANs may produce pictures that translate to a
description given a text input, such as a phrase or a caption. This
application might have an impact on how realistic visual material is
produced using text-based instructions.
4. Data Augmentation : GANs can augment present data and increase the
robustness and generalizability of machine-learning models by creating
synthetic data samples.

https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 14/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

5. Data Generation for Training : GANs can enhance the resolution and
quality of low-resolution images. By training on pairs of low-resolution
and high-resolution images, GANs can generate high-resolution images
from low-resolution inputs, enabling improved image quality in various
applications such as medical imaging, satellite imaging, and video
enhancement.

Advantages of GAN
The advantages of the GANs are as follows:

1. Synthetic data generation: GANs can generate new, synthetic data that
resembles some known data distribution, which can be useful for data
augmentation, anomaly detection, or creative applications.
2. High-quality results: GANs can produce high-quality, photorealistic
results in image synthesis, video synthesis, music synthesis, and other
tasks.
3. Unsupervised learning: GANs can be trained without labeled data,
making them suitable for unsupervised learning tasks, where labeled
data is scarce or difficult to obtain.
4. Versatility: GANs can be applied to a wide range of tasks, including
image synthesis, text-to-image synthesis, image-to-image translation,
anomaly detection, data augmentation, and others.

Disadvantages of GAN
The disadvantages of the GANs are as follows:

1. Training Instability: GANs can be difficult to train, with the risk of


instability, mode collapse, or failure to converge.
2. Computational Cost: GANs can require a lot of computational resources
and can be slow to train, especially for high-resolution images or large
datasets.
3. Overfitting: GANs can overfit the training data, producing synthetic data
that is too similar to the training data and lacking diversity.
4. Bias and Fairness: GANs can reflect the biases and unfairness present in
the training data, leading to discriminatory or biased synthetic data.
5. Interpretability and Accountability: GANs can be opaque and difficult to
interpret or explain, making it challenging to ensure accountability,
transparency, or fairness in their applications.

https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 15/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

GAN(Generative Adversarial Network)- FAQs

Q1. What is a Generative Adversarial Network(GAN)?

An artificial intelligence model known as a GAN is made up of two


neural networks—a discriminator and a generator—that were
developed in tandem using adversarial training. The discriminator
assesses the new data instances for authenticity, while the generator
produces new ones.

Q2. What are the main applications of GAN?

Generating images and videos, transferring styles, enhancing data,


translating images to other images, producing realistic synthetic data
for machine learning model training, and super-resolution are just a
few of the many uses for GANs.

Q3. What challenges do GAN face?

GANs encounter difficulties such training instability, mode collapse


(when the generator generates a limited range of samples), and
striking the correct balance between the discriminator and generator.
It’s frequently necessary to carefully build the model architecture and
tune the hyperparameters.

Q4. How are GAN evaluated?

The produced samples’ quality, diversity, and resemblance to real data


are the main criteria used to assess GANs. For quantitative
assessment, metrics like the Fréchet Inception Distance (FID) and
Inception Score are frequently employed.

https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 16/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

Q5. Can GAN be used for tasks other than image generation?

Yes, different tasks can be assigned to GANs. Text, music, 3D models,


and other things have all been generated with them. The usefulness of
conditional GANs is expanded by enabling the creation of specific
content under certain input conditions.

Q6. What are some famous architectures of GANs?

A few well-known GAN architectures are Progressive GAN (PGAN),


Wasserstein GAN (WGAN), Conditional GAN (cGAN), Deep
Convolutional GAN (DCGAN), and Vanilla GAN. Each has special
qualities and works best with particular kinds of data and tasks.

Now get an additional 30% off on all GfG courses of your choice. Also get
90% Course fee refund in just 90 days. Dual savings offer ending soon,
avail today!

36 Suggest improvement

Previous Next

Basics of Generative Adversarial Use Cases of Generative Adversarial


Networks (GANs) Networks

Share your thoughts in the comments Add Your Comment

Similar Reads
https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 17/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

Conditional Generative Adversarial Wasserstein Generative Adversarial


Network Networks (WGANs) Convergence and
Optimization

Generative Adversarial Networks Difference between GAN vs DCGAN.


(GANs) in PyTorch

What is Language Revitalization in Differences between Conversational AI


Generative AI? and Generative AI

10 Best Generative AI Tools to Refine 5 Top Generative AI Design Tools in


Your Content Strategy 2024 [Free & Paid]

What is the difference between


What is Generative AI? Generative and Discriminative
algorithm?

R Rahul_Roy

Article Tags : python , AI-ML-DS , Deep Learning


Practice Tags : python

A-143, 9th Floor, Sovereign Corporate


Tower, Sector-136, Noida, Uttar Pradesh -
201305

https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 18/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks

Company Explore
About Us Job-A-Thon Hiring Challenge
Legal Hack-A-Thon
Careers GfG Weekly Contest
In Media Offline Classes (Delhi/NCR)
Contact Us DSA in JAVA/C++
Advertise with us Master System Design
GFG Corporate Solution Master CP
Placement Training Program GeeksforGeeks Videos
Geeks Community

Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL DSA Interview Questions
R Language Competitive Programming
Android Tutorial

Data Science & ML Web Technologies


Data Science With Python HTML
Data Science For Beginner CSS
Machine Learning Tutorial JavaScript
ML Maths TypeScript
Data Visualisation Tutorial ReactJS
Pandas Tutorial NextJS
NumPy Tutorial NodeJs
NLP Tutorial Bootstrap
Deep Learning Tutorial Tailwind CSS

Python Tutorial Computer Science


Python Programming Examples GATE CS Notes
Django Tutorial Operating Systems
Python Projects Computer Network
Python Tkinter Database Management System
Web Scraping Software Engineering
OpenCV Tutorial Digital Logic Design
Python Interview Question Engineering Maths

DevOps System Design


Git High Level Design
AWS Low Level Design
Docker UML Diagrams

https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 19/20
4/29/24, 4:22 PM Generative Adversarial Network (GAN) - GeeksforGeeks
Kubernetes Interview Guide
Azure Design Patterns
GCP OOAD
DevOps Roadmap System Design Bootcamp
Interview Questions

School Subjects Commerce


Mathematics Accountancy
Physics Business Studies
Chemistry Economics
Biology Management
Social Science HR Management
English Grammar Finance
Income Tax

UPSC Study Material Preparation Corner


Polity Notes Company-Wise Recruitment Process
Geography Notes Resume Templates
History Notes Aptitude Preparation
Science and Technology Notes Puzzles
Economy Notes Company-Wise Preparation
Ethics Notes Companies
Previous Year Papers Colleges

Competitive Exams More Tutorials


JEE Advanced Software Development
UGC NET Software Testing
SSC CGL Product Management
SBI PO Project Management
SBI Clerk Linux
IBPS PO Excel
IBPS Clerk All Cheat Sheets

Free Online Tools Write & Earn


Typing Test Write an Article
Image Editor Improve an Article
Code Formatters Pick Topics to Write
Code Converters Share your Experiences
Currency Converter Internships
Random Number Generator
Random Password Generator

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

https://www.geeksforgeeks.org/generative-adversarial-network-gan/ 20/20
What is a Boltzmann machine?

A Boltzmann machine is an unsupervised deep learning model in which every node is connected to
every other node. It is a type of recurrent neural network, and the nodes make binary decisions with
some level of bias.

These machines are not deterministic deep learning models, they are stochastic or generative deep
learning models. They are representations of a system.

A Boltzmann machine has two kinds of nodes

 Visible nodes:
These are nodes that can be measured and are measured.

 Hidden nodes:
These are nodes that cannot be measured or are not measured.

According to some experts, a Boltzmann machine can be called a stochastic Hopfield network which
has hidden units. It has a network of units with an ‘energy’ defined for the overall network.

Boltzmann machines seek to reach thermal equilibrium. It essentially looks to optimize global
distribution of energy. But the temperature and energy of the system are relative to laws of
thermodynamics and are not literal.

A Boltzmann machine is made up of a learning algorithm that enables it to discover interesting


features in datasets composed of binary vectors. The learning algorithm tends to be slow in
networks that have many layers of feature detectors but it is possible to make it faster by
implementing a learning layer of feature detectors.

They use stochastic binary units to reach probability distribution equilibrium (to minimize energy). It
is possible to get multiple Boltzmann machines to collaborate together to form far more
sophisticated systems like deep belief networks.

The Boltzmann machine is named after Ludwig Boltzmann, an Austrian scientist who came up with
the Boltzmann distribution. However, this type of network was first developed by Geoff Hinton, a
Stanford Scientist.
What is the Boltzmann distribution?

The Boltzmann distribution is a probability distribution that gives the probability of a system being in
a certain state as a function of that state's energy and the temperature of the system.

It was formulated by Ludwig Boltzmann in 1868 and is also known as the Gibbs distribution.

What are Boltzmann machines used for?

The main aim of a Boltzmann machine is to optimize the solution of a problem. To do this, it
optimizes the weights and quantities related to the specific problem that is assigned to it. This
technique is employed when the main aim is to create mapping and to learn from the attributes and
target variables in the data. If you seek to identify an underlying structure or the pattern within the
data, unsupervised learning methods for this model are regarded to be more useful. Some of the
most widely used unsupervised learning methods are clustering, dimensionality reduction, anomaly
detection and creating generative models.

All of these techniques have a different objective of detecting patterns like identifying latent
grouping, finding irregularities in the data, or even generating new samples from the data that is
available. You can even stack these networks in layers to build deep neural networks that capture
highly complicated statistics. Restricted Boltzmann machines are widely used in the domain of
imaging and image processing as well because they have the ability to model continuous data that
are common to natural images. They are even used to solve complicated quantum mechanical
many-particle problems or classical statistical physics problems like the Ising and Potts classes of
models.

How does a Boltzmann machine work?

Boltzmann machines are non-deterministic (stochastic) generative Deep Learning models that only
have two kinds of nodes - hidden and visible nodes. They don’t have any output nodes, and that’s
what gives them the non-deterministic feature. They learn patterns without the typical 1 or 0 type
output through which patterns are learned and optimized using Stochastic Gradient Descent.

A major difference is that unlike other traditional networks (A/C/R) which don’t have any
connections between the input nodes, Boltzmann Machines have connections among the input
nodes. Every node is connected to all other nodes irrespective of whether they are input or hidden
nodes. This enables them to share information among themselves and self-generate subsequent
data. You’d only measure what’s on the visible nodes and not what’s on the hidden nodes. After the
input is provided, the Boltzmann machines are able to capture all the parameters, patterns and
correlations among the data. It is because of this that they are known as deep generative models
and they fall into the class of Unsupervised Deep Learning.
Types of Boltzmann Machines:

 Restricted Boltzmann Machines (RBMs)

 Deep Belief Networks (DBNs)

 Deep Boltzmann Machines (DBMs)

Restricted Boltzmann Machines (RBMs):

In a full Boltzmann machine, each node is connected to every other node and hence the connections
grow exponentially. This is the reason we use RBMs. The restrictions in the node connections in
RBMs are as follows –

 Hidden nodes cannot be connected to one another.

 Visible nodes connected to one another.

Deep Belief Networks (DBNs):

Suppose we stack several RBMs on top of each other so that the first RBM outputs are the input to
the second RBM and so on. Such networks are known as Deep Belief Networks. The connections
within each layer are undirected (since each layer is an RBM). Simultaneously, those in between the
layers are directed (except the top two layers – the connection between the top two layers is
undirected). There are two ways to train the DBNs-

Greedy Layer-wise Training Algorithm – The RBMs are trained layer by layer. Once the individual
RBMs are trained (that is, the parameters – weights, biases are set), the direction is set up between
the DBN layers.

Wake-Sleep Algorithm – The DBN is trained all the way up (connections going up – wake) and then
down the network (connections going down — sleep).

Therefore, we stack the RBMs, train them, and once we have the parameters trained, we make sure
that the connections between the layers only work downwards (except for the top two layers).

Deep Boltzmann Machines (DBMs):

DBMs are similar to DBNs except that apart from the connections within layers, the connections
between the layers are also undirected (unlike DBN in which the connections between layers are
directed). DBMs can extract more complex or sophisticated features and hence can be used for
more complex tasks.
Convolutional Boltzmann Machine
A Convolutional Boltzmann Machine (CBM) is an extension of the Boltzmann Machine, specifically
designed to handle spatially structured data like images. By leveraging convolutional layers, CBMs
can capture local dependencies and hierarchical features more effectively than traditional
Boltzmann Machines. Here's an overview of Convolutional Boltzmann Machines:

Boltzmann Machines Recap

Boltzmann Machines are a type of stochastic recurrent neural network that can learn a probability
distribution over its set of inputs. They consist of visible and hidden units and use a process called
Gibbs sampling to learn the distribution.

Convolutional Boltzmann Machine (CBM) Overview

CBMs incorporate convolutional operations into the Boltzmann Machine framework, making them
particularly well-suited for image data. They share parameters across spatial locations, which helps
in capturing local features and reducing the number of parameters.

Structure of a Convolutional Boltzmann Machine

1. Visible Layer: This layer corresponds to the input data, such as images. Each visible unit
represents a pixel or a small patch of the input image.

2. Hidden Layers: These layers consist of feature maps obtained through convolutional
operations. Each hidden unit is connected to a local region of the input, similar to how
convolutional layers operate in Convolutional Neural Networks (CNNs).

3. Weights and Biases: CBMs have shared weights (filters) and biases for the convolutional
operations. The weights determine how local patches of the input are combined to produce
the feature maps in the hidden layers.

4. Energy Function: The energy function defines the probability distribution of the network. In
CBMs, the energy function incorporates convolutional operations and can be written as:

𝐸(𝑣,ℎ)=−∑𝑖,𝑗𝑣𝑖,𝑗∑𝑘(𝑊𝑘∗ℎ𝑘)𝑖,𝑗−∑𝑏𝑏𝑏𝑣𝑖,𝑗−∑𝑘𝑐𝑘ℎ𝑘E(v,h)=−i,j∑vi,jk∑(Wk∗hk)i,j−b∑bbvi,j−k∑ckhk

where 𝑣v is the visible layer, ℎh is the hidden layer, 𝑊𝑘Wk are the convolutional filters, 𝑏𝑏bb are
biases for the visible layer, and 𝑐𝑘ck are biases for the hidden layer.

Training a Convolutional Boltzmann Machine

Training a CBM involves adjusting the weights and biases to minimize the energy of the system,
which corresponds to maximizing the likelihood of the observed data. The training process typically
involves the following steps:

1. Positive Phase: Compute the positive gradient using the input data. This phase involves
calculating the activation probabilities of the hidden units given the visible units (input data).

2. Negative Phase: Compute the negative gradient by running the Gibbs sampling process to
generate samples from the model. This phase involves reconstructing the visible units from
the hidden units and then calculating the activation probabilities of the hidden units again.
3. Parameter Update: Update the weights and biases using the difference between the
positive and negative gradients. This can be done using gradient descent or other
optimization techniques.

Applications of Convolutional Boltzmann Machines

CBMs can be used in various applications, particularly those involving image data. Some common
applications include:

 Image Recognition: CBMs can learn hierarchical features from images, making them useful
for tasks like object recognition and classification.

 Image Denoising: By learning the distribution of clean images, CBMs can be used to remove
noise from corrupted images.

 Image Generation: CBMs can generate new images by sampling from the learned
distribution, making them useful for generative modeling tasks.

Advantages and Challenges

Advantages:

 Parameter Sharing: By sharing weights across spatial locations, CBMs reduce the number of
parameters, making them more efficient and scalable for large images.

 Local Feature Learning: CBMs can capture local patterns and hierarchical features, similar to
CNNs, which is beneficial for image data.

Challenges:

 Training Complexity: Training CBMs can be computationally intensive due to the need for
Gibbs sampling and the iterative update process.

 Convergence Issues: Like other Boltzmann Machines, CBMs can face challenges in achieving
stable convergence during training.

Convolutional Boltzmann Machines extend the capabilities of traditional Boltzmann Machines by


incorporating convolutional operations, making them powerful tools for image-related tasks.
However, their complexity and computational demands require careful consideration during
implementation and training.
A biological neuron is a specialized cell found in the nervous system that processes and transmits
information through electrical and chemical signals. Neurons are the fundamental units of the brain
and nervous system, responsible for carrying out the communication necessary for all bodily
functions, including sensory input, motor control, and cognitive processes.

Structure of a Neuron

1. Cell Body (Soma):

 Contains the nucleus and other organelles.

 Responsible for maintaining the cell's health and functionality.

2. Dendrites:

 Branched extensions from the cell body.

 Receive signals from other neurons and conduct these signals toward the cell body.

3. Axon:

 A long, slender projection that conducts electrical impulses away from the cell body.

 Ends in terminal branches that release neurotransmitters to communicate with


other neurons.

4. Axon Hillock:

 The region where the axon originates from the cell body.

 Plays a crucial role in initiating the electrical signal known as the action potential.

5. Myelin Sheath:

 A fatty layer that covers the axon in segments, produced by glial cells.

 Increases the speed of electrical transmission along the axon.

6. Nodes of Ranvier:

 Gaps in the myelin sheath where ion channels are concentrated.

 Facilitate rapid conduction of nerve impulses through a process called saltatory


conduction.

7. Synapse:

 The junction between the terminal branches of one neuron and the dendrites or cell
body of another.

 Includes the presynaptic terminal, synaptic cleft, and postsynaptic membrane.

Function of Neurons

 Signal Reception: Neurons receive signals from other neurons through dendrites. These
signals can be excitatory or inhibitory.

 Signal Integration: The cell body integrates incoming signals and, if the cumulative signal is
strong enough, generates an action potential at the axon hillock.
 Signal Transmission: The action potential travels along the axon to the terminal branches.

 Signal Output: At the synapse, the action potential triggers the release of neurotransmitters
into the synaptic cleft. These chemicals bind to receptors on the postsynaptic neuron,
propagating the signal.

Types of Neurons

1. Sensory Neurons:

 Transmit information from sensory receptors to the central nervous system.

2. Motor Neurons:

 Convey commands from the central nervous system to muscles and glands.

3. Interneurons:

 Connect neurons within the central nervous system and integrate sensory input with
motor output.

Electrical and Chemical Signaling

 Electrical Signaling: Involves the propagation of action potentials, rapid changes in


membrane potential due to the movement of ions (primarily sodium and potassium) across
the neuron's membrane.

 Chemical Signaling: Involves neurotransmitters released from synaptic vesicles in the


presynaptic terminal, crossing the synaptic cleft, and binding to receptors on the
postsynaptic neuron.

Neuroplasticity

 Structural Plasticity: Changes in the structure of neurons, such as the growth of new
dendrites or synapses, in response to experience or injury.

 Functional Plasticity: Changes in the strength of synaptic connections, often referred to as


synaptic plasticity, which includes processes like long-term potentiation (LTP) and long-term
depression (LTD).
Artificial Neuron model

Artificial Neural Networks


Artificial Neural Networks contain artificial neurons which are called units. These units are
arranged in a series of layers that together constitute the whole Artificial Neural Network in
a system. A layer can have only a dozen units or millions of units as this depends on how the
complex neural networks will be required to learn the hidden patterns in the dataset.
Commonly, Artificial Neural Network has an input layer, an output layer as well as hidden
layers. The input layer receives data from the outside world which the neural network needs
to analyze or learn about. Then this data passes through one or multiple hidden layers that
transform the input into data that is valuable for the output layer. Finally, the output layer
provides an output in the form of a response of the Artificial Neural Networks to input data
provided.
In the majority of neural networks, units are interconnected from one layer to another. Each
of these connections has weights that determine the influence of one unit on another unit.
As the data transfers from one unit to another, the neural network learns more and more
about the data which eventually results in an output from the output layer.
Artificial neurons vs Biological neurons
The concept of artificial neural networks comes from biological neurons found in animal
brains So they share a lot of similarities in structure and function wise.
 Structure: The structure of artificial neural networks is inspired by biological
neurons. A biological neuron has a cell body or soma to process the impulses,
dendrites to receive them, and an axon that transfers them to other neurons. The
input nodes of artificial neural networks receive input signals, the hidden layer nodes
compute these input signals, and the output layer nodes compute the final output by
processing the hidden layer’s results using activation functions.

Biological Neuron Artificial Neuron

Dendrite Inputs

Cell nucleus or Soma Nodes

Synapses Weights

Axon Output

 Synapses: Synapses are the links between biological neurons that enable the
transmission of impulses from dendrites to the cell body. Synapses are the weights
that join the one-layer nodes to the next-layer nodes in artificial neurons. The
strength of the links is determined by the weight value.
 Learning: In biological neurons, learning happens in the cell body nucleus or soma,
which has a nucleus that helps to process the impulses. An action potential is
produced and travels through the axons if the impulses are powerful enough to
reach the threshold. This becomes possible by synaptic plasticity, which
represents the ability of synapses to become stronger or weaker over time in
reaction to changes in their activity. In artificial neural networks, backpropagation
is a technique used for learning, which adjusts the weights between nodes according
to the error or differences between predicted and actual outcomes.
Biological Neuron Artificial Neuron

Synaptic plasticity Backpropagations

 Activation: In biological neurons, activation is the firing rate of the neuron which
happens when the impulses are strong enough to reach the threshold. In artificial
neural networks, A mathematical function known as an activation function maps
the input to the output, and executes activations.
Bias in ANN
Bias in an ANN is a parameter added to the input sum of a neuron before applying the
activation function. It is similar to the intercept term in a linear equation and serves to shift
the activation function to the left or right, allowing the neuron to better fit the data.
Key Points About Bias:
1. Flexibility: Bias increases the flexibility of the model by allowing neurons to have an
output even when all inputs are zero. This helps the network to learn patterns that
do not pass through the origin.
2. Equation: For a neuron 𝑗j, the output 𝑦𝑗 is typically computed as: 𝑦𝑗=𝑓(∑𝑖𝑤𝑖𝑗𝑥𝑖+𝑏𝑗)
where:
 𝑓 is the activation function.
 𝑤𝑖𝑗 are the weights for inputs 𝑥𝑖xi.
 𝑏𝑗 is the bias term.
 ∑ represents the summation over all input connections to the neuron.
Threshold in ANN
Threshold in the context of ANNs is the value that the neuron's input sum must reach or
exceed for the neuron to become activated. Historically, in simpler models like perceptrons,
this was implemented using a step activation function where the neuron fires (outputs 1) if
the input sum exceeds the threshold and does not fire (outputs 0) otherwise.
Modern Interpretation:
 Smooth Activation Functions: Modern ANNs use continuous, differentiable
activation functions (like sigmoid, tanh, or ReLU) instead of step functions. These
functions do not have a hard threshold but have an implicit threshold determined by
the shape of the function.
 Sigmoid Function: Smoothly transitions from 0 to 1, centered around 0.
 ReLU Function: Outputs zero for any negative input and outputs the input
value for any positive input, effectively creating a threshold at zero.
1. **Bias**: Prevents the network from being overly restrictive, enabling neurons to
activate even when inputs are zero or very small.
2. **Threshold**: Determines the condition under which neurons fire, shaped by the choice
of activation function, allowing for more nuanced and complex decision boundaries.
1. McCulloch-Pitts Model of Neuron
The McCulloch-Pitts neural model, which was the earliest ANN model, has only two types of
inputs — Excitatory and Inhibitory. The excitatory inputs have weights of positive
magnitude and the inhibitory weights have weights of negative magnitude. The inputs of
the McCulloch-Pitts neuron could be either 0 or 1. It has a threshold function as an
activation function. So, the output signal yout is 1 if the input ysum is greater than or equal
to a given threshold value, else 0.

Simple McCulloch-Pitts neurons can be used to design logical operations. For that purpose,
the connection weights need to be correctly decided along with the threshold function
(rather than the threshold value of the activation function).
So let’s say we have n inputs = { X1, X2, X3, …. , Xn }
And we have n weights for each= {W1, W2, W3, …., W4}
So the summation of weighted inputs X.W = X1.W1 + X2.W2 + X3.W3 +....+ Xn.Wn

If X ≥ ø(threshold value)
Output = 1
Else
Output = 0
Example:
A bank wants to decide if it can sanction a loan or not. There are 2 parameters to decide-
Salary and Credit Score. So there can be 4 scenarios to assess-
1. High Salary and Good Credit Score
2. High Salary and Bad Credit Score
3. Low Salary and Good Credit Score
4. Low Salary and Bad Credit Score
Let X1 = 1 denote high salary and X1 = 0 denote Low salary and X2 = 1 denote good credit
score and X2 = 0 denote bad credit score
Let the threshold value be 2. The truth table is as follows

X1 X2 X1+X2 Loan approved

1 1 2 1

1 0 1 0

0 1 1 0

0 0 0 0
Types Of Learning Rules in ANN

1. Hebbian Learning Rule


Donald Hebb developed it in 1949 as an unsupervised learning algorithm in the neural
network. We can use it to improve the weights of nodes of a network. The following
phenomenon occurs when
 If two neighbor neurons are operating in the same phase at the same period of time,
then the weight between these neurons should increase.
 For neurons operating in the opposite phase, the weight between them should
decrease.
 If there is no signal correlation, the weight does not change, the sign of the weight
between two nodes depends on the sign of the input between those nodes
 When inputs of both the nodes are either positive or negative, it results in a strong
positive weight.
 If the input of one node is positive and negative for the other, a strong negative
weight is present.
2.Perceptron Learning Rule
It was introduced by Rosenblatt. It is an error-correcting rule of a single-layer feedforward
network. it is supervised in nature and calculates the error between the desired and actual
output and if the output is present then only adjustments of weight are done.
3. Delta Learning Rule
It was developed by Bernard Widrow and Marcian Hoff and It depends on supervised
learning and has a continuous activation function. It is also known as the Least Mean
Square method and it minimizes error over all the training patterns.
It is based on a gradient descent approach which continues forever. It states that the
modification in the weight of a node is equal to the product of the error and the
input where the error is the difference between desired and actual output.
4. Correlation Learning Rule
The correlation learning rule follows the same similar principle as the Hebbian
learning rule,i.e., If two neighbor neurons are operating in the same phase at the
same period of time, then the weight between these neurons should be more
positive. For neurons operating in the opposite phase, the weight between them
should be more negative but unlike the Hebbian rule, the correlation rule is
supervised in nature here, the targeted response is used for the calculation of the
change in weight.
In Mathematical form:
δw=αxitj
where δw=change in weight,α=learning rate,xi=set of the input vector, and tj=target
value
5. Out Star Learning Rule
It was introduced by Grossberg and is a supervised training procedure.
Out Star Learning Rule is implemented when nodes in a network are arranged in a
layer. Here the weights linked to a particular node should be equal to the targeted
outputs for the nodes connected through those same weights. Weight change is thus
calculated as=δw=α(t-y)
Where α=learning rate, y=actual output, and t=desired output for n layer nodes.
6. Competitive Learning Rule

It is also known as the Winner-takes-All rule and is unsupervised in nature. Here all
the output nodes try to compete with each other to represent the input pattern and
the winner is declared according to the node having the most outputs and is given
the output 1 while the rest are given 0.
Single-Layer Perceptron (SLP)
A Single-Layer Perceptron (SLP) is the simplest type of artificial neural network. It consists of
a single layer of output nodes connected to an input layer, with no hidden layers in
between.
Structure:
 Input Layer: The neurons in this layer receive the input features.
 Output Layer: The neurons in this layer produce the final output.
Working:
 Weights: Each input feature is assigned a weight.
 Bias: A bias term is added to the input sum.
 Activation Function: The sum of weighted inputs and bias is passed through an
activation function to produce the output.
Multi-Layer Perceptron (MLP)
A Multi-Layer Perceptron (MLP) is an extension of the single-layer perceptron and includes
one or more hidden layers between the input and output layers. It is capable of modeling
complex relationships and solving problems that are not linearly separable.
Structure:
 Input Layer: Receives the input features.
 Hidden Layers: One or more layers of neurons between the input and output layers.
 Output Layer: Produces the final output.

Working:
 Weights and Biases: Each neuron has its own set of weights and a bias.
 Activation Functions: Non-linear activation functions (like ReLU, sigmoid, or tanh)
are applied to the weighted sum of inputs at each neuron.
 Forward Propagation: Inputs are propagated through the network from the input
layer to the output layer, applying weights, biases, and activation functions at each
layer.
Applications;
Data Compression
Time Series Prediction
Character Recognition
Autonomous Driving
Backpropagation Algorithm
Backpropagation is a supervised learning algorithm used for training MLPs. It aims to
minimize the error by adjusting the weights and biases based on the error gradient.
Steps:
1. Initialization:
 Initialize weights and biases randomly (or using a specific initialization
strategy).
2. Forward Propagation:
 Input data is passed through the network layer by layer.
 At each layer, compute the weighted sum and apply the activation function
to get the output for the next layer.
 Compute the final output at the output layer.
3. Compute Error:
 Calculate the error (loss) by comparing the predicted output with the actual
target value using a loss function (e.g., mean squared error for regression or
cross-entropy loss for classification).
4. Backward Propagation:
 Calculate Gradients: Compute the gradient of the loss function with respect
to each weight and bias by applying the chain rule of calculus.
 For the output layer, the gradient of the loss function is directly
computed.
 For hidden layers, the gradient is propagated backward using the
gradients from the layer above.
Iteration:
 Repeat forward and backward propagation for a set number of epochs or
until the error is minimized to a satisfactory level.
BackPropagation Algorithm
The backpropagation algorithm is used in a Multilayer perceptron neural network to
increase the accuracy of the output by reducing the error in predicted output and actual
output.
According to this algorithm,
 Calculate the error after calculating the output from the Multilayer perceptron
neural network.
 This error is the difference between the output generated by the neural network
and the actual output. The calculated error is fed back to the network, from the
output layer to the hidden layer.
 Now, the output becomes the input to the network.
 The model reduces error by adjusting the weights in the hidden layer.
 Calculate the predicted output with adjusted weight and check the error. The
process is recursively used till there is minimum or no error.
 This algorithm helps in increasing the accuracy of the neural network.
Advantages of Using the Backpropagation Algorithm in Neural Networks
Backpropagation, a fundamental algorithm in training neural networks, offers several
advantages that make it a preferred choice for many machine learning tasks. Here, we
discuss some key advantages of using the backpropagation algorithm:
1. Ease of Implementation: Backpropagation does not require prior knowledge of
neural networks, making it accessible to beginners. Its straightforward nature
simplifies the programming process, as it primarily involves adjusting weights
based on error derivatives.
2. Simplicity and Flexibility: The algorithm’s simplicity allows it to be applied to a
wide range of problems and network architectures. Its flexibility makes it suitable
for various scenarios, from simple feedforward networks to complex recurrent or
convolutional neural networks.
3. Efficiency: Backpropagation accelerates the learning process by directly updating
weights based on the calculated error derivatives. This efficiency is particularly
advantageous in training deep neural networks, where learning features of a
function can be time-consuming.

Summary
 SLP: Suitable for simple, linearly separable problems.
 MLP: Can handle complex, non-linear relationships due to its multiple layers and
non-linear activation functions.
 Backpropagation: Efficiently trains MLPs by minimizing error through gradient
descent, adjusting weights and biases iteratively.
What is Gradient Descent?

Gradient descent is an optimization algorithm used in machine learning to

minimize the cost function by iteratively adjusting parameters in the direction of

the negative gradient, aiming to find the optimal set of parameters.

The cost function represents the discrepancy between the predicted output of the

model and the actual output. Gradient descent aims to find the parameters that

minimize this discrepancy and improve the model’s performance.

The algorithm operates by calculating the gradient of the cost function, which

indicates the direction and magnitude of the steepest ascent. However, since the

objective is to minimize the cost function, gradient descent moves in the opposite

direction of the gradient, known as the negative gradient direction.

By iteratively updating the model’s parameters in the negative gradient direction,

gradient descent gradually converges towards the optimal set of parameters that

yields the lowest cost. The learning rate, a hyperparameter, determines the step

size taken in each iteration, influencing the speed and stability of convergence.

Gradient descent can be applied to various machine learning algorithms,

including linear regression, logistic regression, neural networks, and support

vector machines. It provides a general framework for optimizing models by

iteratively refining their parameters based on the cost function.


RBFN

RBFN stands for Radial Basis Function Network. It's a type of artificial neural

network that uses radial basis functions as activation functions. Unlike traditional

feedforward neural networks, where neurons are connected in layers and pass

their signals forward, RBFNs typically have three layers: input, hidden, and

output.

They offer advantages like fast training times and good generalization

capabilities. However, proper parameter tuning, including the number and

placement of radial basis functions, is essential for optimal performance.

Here's a breakdown of the layers:

1. Input Layer: This layer consists of input nodes, each representing a

feature of the input data.

2. Hidden Layer: The hidden layer contains units with radial basis functions

as activation functions. These functions evaluate the distance between the

input data and the center of each unit. Commonly used radial basis

functions include Gaussian, multi-quadric, and inverse multi-quadric

functions.

3. Output Layer: This layer produces the network's output based on the

activations of the hidden layer units.


Applications of RBFNs include:

1. Function Approximation: RBFNs can approximate complex functions,

making them useful in various mathematical and engineering applications.

2. Pattern Recognition: They are employed in tasks such as classification

and clustering. For example, in image recognition, RBFNs can classify

images into different categories based on their features.

3. Time Series Prediction: RBFNs can be used to predict future values in

time series data, such as stock prices, weather patterns, or energy

consumption.

4. Control Systems: RBFNs can be applied to control systems for tasks

such as adaptive control and fault diagnosis.

5. Financial Forecasting: RBFNs are used in financial applications for tasks

like stock market prediction, credit risk assessment, and algorithmic

trading.

You might also like