Unit 4: Deep Learning
1. Introduction to Deep Learning
Definition:
Deep Learning is a branch of Machine Learning that uses algorithms called
Artificial Neural Networks (ANNs) with many layers to model complex
patterns in large datasets.
Key Points:
Inspired by the structure of the human brain (neurons and synapses).
Focuses on feature extraction and pattern recognition without human
intervention.
Useful in vision, language processing, robotics, etc.
Difference from Traditional Machine Learning:
Traditional ML Deep Learning
Needs manual feature extraction Learns features automatically
Shallow models (e.g., decision trees, SVM) Deep models with many layers
Less accurate on unstructured data Very accurate on image, text, sound
2. Why Deep Learning?
Reasons to use Deep Learning:
1. High Performance:
Achieves state-of-the-art results in tasks like image classification (e.g.,
ImageNet), speech recognition (e.g., Google Assistant), and language
translation.
2. Big Data Friendly:
Works better as data size increases—traditional models fail to scale like
this.
3. Automatic Feature Extraction:
Eliminates the need for domain-specific feature engineering.
4. Complex Problem Solving:
Handles problems with high variability, such as face recognition across
different lighting, angles, etc.
5. Real-Time Application:
Powers applications like real-time object detection in autonomous
vehicles.
3. Building Blocks of Deep Neural Network
A Deep Neural Network (DNN) is made up of multiple layers of artificial
neurons. Here's a breakdown:
a. Neurons (Perceptrons):
Each neuron takes multiple inputs, applies weights, adds a bias, and passes it
through an activation function to produce an output.
Output = Activation( (w1 × x1) + (w2 × x2) + ... + b )
b. Layers:
1. Input Layer:
Receives raw input (e.g., pixels in an image, values in a dataset).
2. Hidden Layers:
Perform computations. Deep networks have many hidden layers—this is
the "deep" in deep learning.
3. Output Layer:
Gives final prediction or classification.
c. Activation Functions:
Introduce non-linearity, enabling the network to learn complex patterns.
ReLU (Rectified Linear Unit): f(x) = max(0, x)
Sigmoid: Squeezes output to (0,1)
Tanh: Squeezes output to (-1,1)
d. Loss Function:
Measures the difference between predicted and actual output.
Examples: Mean Squared Error (MSE), Cross-Entropy Loss
e. Optimizer:
Updates the weights to minimize the loss function.
Examples: SGD (Stochastic Gradient Descent), Adam, RMSprop
f. Backpropagation:
Algorithm used to compute gradients for each weight in the network, so they can
be updated properly.
4. Introduction to RNN (Recurrent Neural Networks)
Definition:
RNNs are a type of neural network designed to process sequential data by
maintaining a "memory" of previous inputs through feedback loops.
Key Features:
Handles temporal or time-series data.
Maintains hidden states to remember past input.
Useful for text, speech, and time-series prediction.
Working:
At each time step, the RNN takes the current input and the previous hidden
state to compute the new hidden state.
Applications:
Language Modeling (predict next word)
Sentiment Analysis
Stock Price Prediction
Machine Translation
Limitations:
Hard to train over long sequences due to vanishing gradients.
LSTMs and GRUs are improved versions of RNNs.
5. Introduction to CNN (Convolutional Neural Networks)
Definition:
CNNs are specialized neural networks used primarily for image and video data.
They detect patterns such as edges, textures, shapes, etc.
Key Layers in CNN:
1. Convolutional Layer:
o Applies filters to input to extract features.
o Preserves spatial relationships between pixels.
o A filter is a small matrix (e.g., 3×3) that slides across the image.
2. Activation Function (e.g., ReLU):
o Introduces non-linearity.
3. Pooling Layer:
o Reduces spatial size to decrease computation.
o Max Pooling: Selects the maximum value in a region.
4. Fully Connected Layer:
o Like traditional neural networks.
o Flattens the image and uses it for final classification.
6. CNN Example: Image Classification
Task: Classify an image as cat or dog.
Steps:
1. Input Image: 64×64 RGB image
2. Convolution Layer: Detects edges, colors, textures
3. Pooling Layer: Downsamples image (e.g., from 64×64 to 32×32)
4. More Convolutions and Pooling: Learn higher-level features (e.g.,
eyes, ears)
5. Fully Connected Layer: Takes extracted features to make decision
6. Output Layer:
o Uses Softmax Activation
o Output:
Cat: 92%
Dog: 8%
Applications of CNN:
Face recognition
Medical image analysis
Self-driving car vision
Object detection (YOLO, SSD)
Unit 5: Fuzzy
1. Classical Sets:
A classical (or crisp) set is a well-defined collection of distinct objects or
elements.
In classical sets, an element either belongs to the set (membership =
1) or does not belong (membership = 0).
There is no concept of partial membership.
Mathematically: A = {x | x satisfies a certain property}
Example: Let A be the set of even numbers less than 10. A = {2, 4, 6,
8}. Here, 4 ∈ A (membership = 1), but 5 ∉ A (membership = 0).
2. Fuzzy Sets:
Fuzzy sets generalize classical sets by allowing degrees of membership.
Each element can have a membership value between 0 and 1, denoted by
a membership function μ(x).
This approach is suitable for vague or imprecise information, common
in real-life scenarios.
Example: Let fuzzy set Y represent the set of "young" people.
o A 20-year-old might have μ(20) = 1.0 (definitely young)
o A 30-year-old might have μ(30) = 0.6 (somewhat young)
o A 50-year-old might have μ(50) = 0.1 (barely young)
3. Crisp Relations:
A relation between two classical sets A and B is defined as a subset of the
Cartesian product A × B.
Each pair (a, b) ∈ A × B is either in the relation (true) or not (false).
Example:
o A = {1, 2}, B = {x, y}
o R = {(1, x), (2, y)} is a crisp relation between A and B
Used in database management and formal logic.
Crisp Set: Countability and finiteness are identical properties which are
the collection objects of crisp set. ‘X‘ is a crisp set defined as the group of
elements present over the universal set i.e. U. In this case a random
element is present that may be a part of X or not that means two ways
are possible to define the set. These are first element would become from
set X, or it does not come from X.
Fuzzy Set: The Integration of the elements having a changing degree of
membership in the set is called as fuzzy set. The word “fuzzy” indicates
vagueness, On the other hand, we can say that the replacement among
various degrees of the membership implies that the vague and ambiguity
of the fuzzy set. Hence, the measurement of the membership of the
elements from the universe in the set against a function for detecting the
uncertainty and ambiguity.
[Link] Crisp Set Fuzzy Set
Fuzzy set defines the
Crisp set defines the
1 value between 0 and 1
value is either 0 or 1.
including both 0 and 1.
It is also called a It specifies the degree to
2
classical set. which something is true.
It shows full It shows partial
3
membership membership.
Eg1. She is 18 years Eg1. She is about 18
old. years old.
4
Eg2. Rahul is 1.6m Eg2. Rahul is about 1.6m
tall tall.
Crisp set application
Fuzzy set used in the
5 used for digital
fuzzy controller.
design.
It is bi-valued It is infinite valued
6
function logic. function logic
Full membership
Partial membership
means totally
7 means true to false, yes
true/false, yes/no,
to no, 0 to 1.
0/1.
4. Fuzzy Relations:
Extend crisp relations to include degrees of relationship.
Each pair (a, b) in the relation has a membership value μ(a, b) ∈ [0, 1].
Represented using fuzzy matrices, where each entry indicates strength
of the relation.
Example: R(x, y) = 0.8 could indicate a strong association between x and
y.
Useful in fuzzy inference systems and approximate reasoning.
5. Examples:
Fuzzy Set Example: Fuzzy set T = { (18, 1.0), (25, 0.8), (35, 0.3), (50,
0.0) } for the linguistic variable "young".
Fuzzy Relation Example: "If temperature is high (0.9) and humidity is
high (0.8), then fan speed is fast (0.85)."
6. Properties of Membership Functions:
Membership functions define how each input value is mapped to a
membership value.
Properties include:
o Normality: There exists at least one element x such that μ(x) = 1.
o Convexity: For all x1, x2, and λ ∈ [0,1], μ(λx1 + (1-λ)x2) ≥
min(μ(x1), μ(x2)).
o Support: Set of all elements with non-zero membership.
o Height: Maximum value of the membership function.
o Continuity: A smooth membership function improves accuracy and
avoids abrupt changes.
7. Fuzzification:
Process of converting crisp input values into fuzzy values using
membership functions.
Required in fuzzy inference systems to allow vague reasoning.
Steps:
1. Identify linguistic variables (e.g., temperature).
2. Define membership functions for terms (e.g., cold, warm, hot).
3. Assign input to each fuzzy set.
Example: Input temperature = 30°C
o Cold: 0.1, Warm: 0.7, Hot: 0.3
8. Defuzzification:
The process of converting fuzzy outputs (fuzzy sets) into a single crisp
numerical output.
Used to make real-world decisions based on fuzzy inference.
Common Methods:
o Centroid (Center of Gravity): Calculates weighted average of the
fuzzy set.
o Maximum Membership Principle (Height Method): Chooses
the output value with the highest membership.
o Bisector Method: Finds a point that divides the fuzzy set's area
into two equal halves.
Example: Fan speed fuzzy output: slow (0.2), medium (0.6), fast (0.8) →
Defuzzified value: 75% speed
Fuzzification: It is the method of transforming a crisp quantity(set) into
a fuzzy quantity(set). This can be achieved by identifying the various
known crisp and deterministic quantities as completely nondeterministic
and quite uncertain in nature. This uncertainty may have emerged
because of vagueness and imprecision which then lead the variables to be
represented by a membership function as they can be fuzzy in nature. For
example, when I say the temperature is 45° Celsius the viewer converts
the crisp input value into a linguistic variable like favorable temperature
for the human body, hot or cold.
Defuzzification: It is the inverse of fuzzification. The former one was
used to convert the crisp results into fuzzy results but here the mapping is
done to convert the fuzzy results into crisp results. This process is capable
of generating a non-fuzzy control action which illustrates the possibility
distribution of an inferred fuzzy control action. Defuzzification process can
also be treated as the rounding off process, where fuzzy set having a
group of membership values on the unit interval reduced to a single scalar
quantity.
Difference between Fuzzification and Defuzzification:
[Link] Compariso Fuzzificatio Defuzzificatio
. n n n
Precise
data is Imprecise
converted data is
into converted
imprecise into precise
1. Basic data. data.
Defuzzificatio
n is the
inverse
process of
Fuzzificatio fuzzification
n is the where the
method of mapping is
converting done to
a crisp convert the
quantity fuzzy results
into a fuzzy into crisp
2. Definition quantity. results.
Like, Stepper
Like, motor and
3. Example Voltmeter D/A converter
Maximum
membership
Intuition, principle,
inference, centroid
rank method,
ordering, weighted
angular average
fuzzy sets, method,
neural center of
network, sums,
4. Methods etcetera. etcetera.
It is quite It is quite
5. Complexity simple. complicated.
It can use
IF-THEN
It uses the
rules for
center of
fuzzifying
gravity
the crisp
methods to
6. Use value.
find the
centroid of
the sets.
9. Application of Fuzzy Control:
Fuzzy control systems mimic human reasoning using rules with fuzzy
logic.
Benefits:
o Handles imprecise, uncertain, or noisy inputs
o No need for precise mathematical model of the system
Applications:
1. Home Appliances:
Washing Machines: Adjust wash time based on dirt level and
load.
Air Conditioners: Modify temperature based on room temp
and occupancy.
2. Automotive Systems:
Anti-lock Braking System (ABS)
Automatic Gear Shifting
Cruise Control
3. Industrial Automation:
Control of chemical processes with vague sensors or inputs.
4. Robotics and AI:
Human-robot interaction with natural language commands.
Unit 6: Genetic Algorithms and Their Applications \
1. Fundamentals of Genetic Algorithms (GA):
Genetic Algorithms are a class of optimization algorithms inspired by the
mechanisms of natural evolution and genetics, first introduced by John
Holland in the 1970s.
They are based on the principles of natural selection, genetic
inheritance, and survival of the fittest.
GAs are suitable for solving complex problems where the search space is
large, nonlinear, or poorly understood.
This section introduces the basic terminology required to understand GAs.
Also, a generic structure of GAs is presented in both pseudo-code and
graphical forms. The reader is advised to properly understand all the
concepts introduced in this section and keep them in mind when reading
other sections of this tutorial as well.
Basic Terminology
Before beginning a discussion on Genetic Algorithms, it is essential to be
familiar with some basic terminology which will be used throughout this
tutorial.
Population − It is a subset of all the possible (encoded) solutions to the
given problem. The population for a GA is analogous to the population for
human beings except that instead of human beings, we have Candidate
Solutions representing human beings.
Chromosomes − A chromosome is one such solution to the given
problem.
Gene − A gene is one element position of a chromosome.
Allele − It is the value a gene takes for a particular chromosome.
Genotype − Genotype is the population in the computation space. In the
computation space, the solutions are represented in a way which can be
easily understood and manipulated using a computing system.
Phenotype − Phenotype is the population in the actual real world
solution space in which solutions are represented in a way they are
represented in real world situations.
Decoding and Encoding − For simple problems, the phenotype and
genotype spaces are the same. However, in most of the cases, the
phenotype and genotype spaces are different. Decoding is a process of
transforming a solution from the genotype to the phenotype space, while
encoding is a process of transforming from the phenotype to genotype
space. Decoding should be fast as it is carried out repeatedly in a GA
during the fitness value calculation.
For example, consider the 0/1 Knapsack Problem. The Phenotype space
consists of solutions which just contain the item numbers of the items to be
picked.
However, in the genotype space it can be represented as a binary string of
length n (where n is the number of items). A 0 at position x represents
that xth item is picked while a 1 represents the reverse. This is a case where
genotype and phenotype spaces are different.
2. Basic Concepts:
Population: A collection of individuals (candidate solutions) that evolves
over generations. The size of the population affects the performance of
the GA.
Chromosome: A representation of a candidate solution. It can be in the
form of binary strings, real-valued vectors, or symbolic representations.
Gene: The smallest unit of a chromosome representing a single variable
or feature of the solution.
Fitness Function: Evaluates and assigns a fitness score to each
individual based on how well it solves the problem. A good fitness function
guides the evolution effectively.
Generation: A complete cycle of selection, crossover, mutation, and
population replacement. Each generation ideally produces better solutions.
We start with an initial population (which may be generated at random or
seeded by other heuristics), select parents from this population for
mating. Apply crossover and mutation operators on the parents to
generate new off-springs. And finally these off-springs replace the existing
individuals in the population and the process repeats. In this way genetic
algorithms actually try to mimic the human evolution to some extent.
Each of the following steps are covered as a separate chapter later in this
tutorial.
3. Working Principle:
1. Initialization: Randomly generate an initial population of chromosomes.
2. Evaluation: Apply the fitness function to determine how good each
chromosome is.
3. Selection: Choose individuals based on fitness. Fitter individuals have a
higher chance of being selected for reproduction.
4. Crossover (Recombination): Pair selected individuals and combine their
genetic material to create offspring.
5. Mutation: Apply random changes to some genes to maintain diversity in
the population.
6. Replacement: Replace the old population with the new offspring, either
fully or partially.
7. Termination: The process repeats for a number of generations or until a
solution of acceptable fitness is found.
4. Inheritance Operators:
Inheritance operators control how genetic material is passed from parents
to offspring.
Main operators:
o Crossover: Combines genetic material of two parents to produce
one or more children.
o Mutation: Introduces small, random changes to maintain diversity
and explore new parts of the solution space.
Operators of Genetic Algorithms
Once the initial generation is created, the algorithm evolves the generation
using following operators –
1) Selection Operator: The idea is to give preference to the individuals
with good fitness scores and allow them to pass their genes to successive
generations.
2) Crossover Operator: This represents mating between individuals. Two
individuals are selected using selection operator and crossover sites are
chosen randomly. Then the genes at these crossover sites are exchanged
thus creating a completely new individual (offspring). For example –
3) Mutation Operator: The key idea is to insert random genes in
offspring to maintain the diversity in the population to avoid premature
convergence. For example –
The whole algorithm can be summarized as –
1) Randomly initialize populations p
2) Determine fitness of population
3) Until convergence repeat:
a) Select parents from population
b) Crossover and generate new population
c) Perform mutation on new population
d) Calculate fitness for new population
5. Crossover Types:
A critical operator for combining and mixing genetic information.
o Single-Point Crossover: One crossover point is selected. The first
part of the first parent is combined with the second part of the
second parent.
o Two-Point Crossover: Two crossover points are selected, and the
genes between these points are swapped.
o Uniform Crossover: Each gene is selected from one of the two
parents randomly based on a mixing ratio.
o Arithmetic Crossover: Offspring are created by taking a linear
combination of parent genes (used in real-valued representations).
Crossover is a genetic operator used to vary the programming of a chromosome
or chromosomes from one generation to the next. Crossover is sexual
reproduction. Two strings are picked from the mating pool at random to
crossover in order to produce superior offspring. The method chosen depends on
the Encoding Method.
Crossover mask: The choice of which parent contributes to the bit position
fI the offspring is given by an additional string called crossover mask similar to
bit masks in unity game engine.
Different types of crossover :
Single Point Crossover: A crossover point on the parent organism string is
selected. All data beyond that point in the organism string is swapped between
the two parent organisms. Strings are characterized by Positional Bias.
Two-Point Crossover : This is a specific case of a N-point Crossover technique.
Two random points are chosen on the individual chromosomes (strings) and the
genetic material is exchanged at these points.
Uniform Crossover: Each gene (bit) is selected randomly from one of the
corresponding genes of the parent chromosomes.
Use tossing of a coin as an example technique.
The crossover between two good solutions may not always yield a better or as
good a solution. Since parents are good, the probability of the child being good
is high. If offspring is not good (poor solution), it will be removed in the next
iteration during “Selection”.
Problems with Crossover:
Depending on coding, simple crossovers can have a high chance to
produce illegal offspring.
E.g. in TSP with simple binary or path coding, most offspring will be illegal
because not all cities will be in the offspring and some cities will be there
more than once.
Uniform crossover can often be modified to avoid this problem
E.g. in TSP with simple path coding:
Where the mask is 1, copy cities from one parent
Where the mask is 0, choose the remaining cities in the order of the other
parent.
6. Inversion and Deletion:
Inversion: A segment of the chromosome is selected and reversed. This
operator can rearrange the structure of genes and help escape local
optima.
Deletion: A segment of the chromosome is removed. Although less
commonly used, it can simplify solutions and reduce overfitting in some
applications.
7. Mutation Operator:
Mutation ensures genetic diversity and prevents premature convergence.
Mutation rate is typically low to avoid random search behavior.
Types of Mutation:
o Bit Flip Mutation: Flips a bit in a binary chromosome (0 becomes
1 and vice versa).
o Swap Mutation: Two genes are randomly selected and swapped.
o Scramble Mutation: A subset of genes is selected and shuffled.
o Gaussian Mutation: Adds a small Gaussian-distributed noise to
real-valued genes.
Mutation Operators
In this section, we describe some of the most commonly used
mutation operators. Like the crossover operators, this is not an
exhaustive list and the GA designer might find a combination of
these approaches or a problem-specific mutation operator more
useful.
Bit Flip Mutation
In this bit flip mutation, we select one or more random bits and flip
them. This is used for binary encoded GAs.
Random Resetting
Random Resetting is an extension of the bit flip for the integer
representation. In this, a random value from the set of permissible
values is assigned to a randomly chosen gene.
Swap Mutation
In swap mutation, we select two positions on the chromosome at
random, and interchange the values. This is common in permutation
based encodings.
Scramble Mutation
Scramble mutation is also popular with permutation
representations. In this, from the entire chromosome, a subset of
genes is chosen and their values are scrambled or shuffled
randomly.
Inversion Mutation
In inversion mutation, we select a subset of genes like in scramble
mutation, but instead of shuffling the subset, we merely invert the
entire string in the subset.
8. Bit-wise Operators:
Operate at the bit level on chromosomes represented as binary strings.
Useful for low-level manipulations of solutions.
Examples:
o AND Operator: Can be used to mask certain genes.
o OR Operator: Can force certain genes to be activated.
o XOR Operator: Useful in symmetric mutation strategies.
o Bit Shifting: Shifts the bit positions to the left or right, useful in
decoding encoded information.
Bit-wise operators operate directly on the binary representation of
chromosomes. These are logical operations performed at the level of
individual bits in binary strings.
Bit-wise operations are crucial for low-level manipulations and are
especially relevant when using binary-encoded genetic algorithms.
Types of Bit-wise Operators:
1. AND Operator ( & ):
o Performs a logical AND operation between two binary strings.
o Only retains bits that are 1 in both strings.
o Usage: Useful for masking specific genes. For instance, to preserve
certain regions of the chromosome during reproduction.
o Example:
Parent A: 1101
Mask: 1011
Result: 1001
2. OR Operator ( | ):
o Performs a logical OR operation between two binary strings.
o Sets each bit to 1 if at least one of the corresponding bits is 1.
o Usage: Forces the activation of certain genes or traits.
o Example:
Parent A: 1001
Mask: 1100
Result: 1101
3. XOR Operator ( ^ ):
o Performs a logical XOR (exclusive OR) operation.
o Sets the bit to 1 if the corresponding bits are different.
o Usage: Can be used in symmetric mutation or crossover operations
to enhance diversity.
o Example:
A: 1010
B: 1100
Result: 0110
4. NOT Operator ( ~ ):
o Inverts all bits (0 becomes 1, and 1 becomes 0).
o Usage: A simple and effective way to introduce mutation.
o Example:
A: 1011
Result: 0100
5. Bit Shifting ( << or >> ):
o Left Shift ( << ): Shifts bits to the left by a specified number of
positions, filling zeros on the right.
o Right Shift ( >> ): Shifts bits to the right, possibly discarding the
rightmost bits.
o Usage: Useful for encoding and decoding chromosome values or
performing arithmetic transformations.
o Example:
A = 0011 (3 in decimal)
A << 1 = 0110 (6 in decimal)
Applications:
Bit-wise operations allow more control over genetic operations and are
used in:
o Efficient chromosome encoding/decoding
o Hybrid GAs with hardware-level optimization
o Performance tuning in embedded or real-time systems
9. Convergence of GA:
Refers to the process of the population stabilizing towards optimal or
near-optimal solutions.
Ideally, the fitness of the best solution improves over generations.
Issues:
o Premature Convergence: The population becomes too similar and
stops evolving before finding the global optimum.
o Genetic Drift: Random changes lead the population away from
optimal solutions.
Preventive Measures:
o Maintain genetic diversity using appropriate mutation and crossover
rates.
o Use elitism (preserve best individuals).
o Introduce new individuals periodically.
Genetic algorithms are probabilistic search optimization techniques, which
operate on a population of chromosomes, representing potential solutions
to the given problem.
In a standard genetic algorithm, binary strings of 1s and 0s represent the
chromosomes. Each chromosome is assigned a fitness value expressing its
quality reflecting the given objective function. Such a population is
evolved by means of reproduction and recombination operators in order to
breed the optimal solution’s chromosome. The evolution keeps running
until some termination condition is fulfilled. The best chromosome
encountered so far is then considered as the found solution.
Genetic algorithms simultaneously carry out exploitation of the promising
regions found so far and exploration of other areas for potentially better
solution.
The weak point of a genetic algorithm is that it often suffers from so-
called premature convergence, which is caused by an early
homogenization of genetic material in the population. This means that no
valuable exploration can be performed anymore.
Schematic Diagram
Details:
Convergence is a phenomenon in evolutionary computation that causes
evolution to halt because precisely every individual in the population is
identical.
Full Convergence might be seen in genetic algorithms using only cross-
over.
Premature convergence is when a population has converged to a single
solution, but that solution is not as high of quality as expected, i.e. the
population has gotten stuck.
However, convergence is not necessarily a negative phenomenon, because
populations often stabilize after a time, in the sense that the best
programs all have a common ancestor and their behaviour is very
similar/identical both to each other and to that of high fitness programs
from the previous generations.
Convergence can be avoided with a variety of diversity generating
techniques.
10. Applications of Genetic Algorithms:
GAs are used in a variety of domains where traditional optimization
methods fail or are inefficient.
A. Engineering:
Structural optimization, design of mechanical parts, circuit design.
B. Machine Learning and AI:
Feature selection for classification tasks.
Evolving weights and structures of neural networks.
C. Robotics:
Path planning for robots in dynamic environments.
Behavior-based robotic systems.
D. Bioinformatics:
DNA sequence alignment.
Protein structure prediction.
E. Finance and Economics:
Portfolio optimization.
Forecasting and trading rule discovery.
F. Game Development:
Designing adaptive AI for non-player characters.
Strategy optimization in competitive games.
G. Scheduling and Resource Allocation:
Job-shop scheduling.
Load balancing in distributed systems.