CT 2
Q1) Explain the terms 'chromosome,' 'gene,' and 'allele' in the context of GAs. Describe the process of 'selection' in
genetic algorithms. What is a 'fitness function' in the context of a genetic algorithm?
1. Chromosome:
In Genetic Algorithms (GAs), a chromosome is a representation of a potential solution to the problem being solved.
It is usually encoded as a binary string, array of integers, or floating-point values, depending on the nature of the
problem.
• Each chromosome in the population represents a single solution.
• The structure of the chromosome encodes decision variables or parameters to be optimized.
Example:
For a solution with 8 binary decision variables, a chromosome could be:
[1, 0, 1, 1, 0, 0, 1, 0]
2. Gene:
A gene is the smallest unit of data in a chromosome. Each gene holds a value that corresponds to one variable of the
problem.
• It represents a part of the total solution.
• A chromosome is made up of multiple genes.
Example:
In the chromosome [1, 0, 1, 1, 0, 0, 1, 0], each digit (like 1, 0, etc.) is a gene.
3. Allele:
An allele is the specific value of a gene at a particular position in the chromosome.
• While a gene represents a slot, the allele is the content of that slot.
Example:
In the chromosome [1, 0, 1, 1, 0, 0, 1, 0], the allele at position 1 is 1, and at position 2 is 0.
4. Selection in Genetic Algorithms:
Selection is a key operation in genetic algorithms where individuals from the current population are chosen to
reproduce (via crossover and mutation) and form the next generation.
• The goal is to favor fitter individuals, thereby guiding the population toward optimal solutions over
generations.
Common Selection Techniques:
• Roulette Wheel Selection:
Probability of selection is proportional to the fitness of individuals. Like a spinning wheel where fitter
solutions occupy larger segments.
• Tournament Selection:
A few individuals are selected randomly, and the best among them is chosen for reproduction.
• Rank Selection:
Individuals are ranked according to fitness, and selection is based on the rank rather than raw fitness values.
5. Fitness Function:
The fitness function is a mathematical function used to evaluate how “good” a solution (chromosome) is with
respect to the desired objective.
• It assigns a fitness score to each individual.
• It determines which solutions are allowed to pass on their genes to the next generation.
Key Points:
• The fitness function is problem-specific.
• It is critical to the success of the genetic algorithm.
Example:
In a job scheduling problem, the fitness function might be:
Fitness = 1 / (Number of conflicts + Idle time)
A chromosome with fewer scheduling conflicts and lower idle time will have a higher fitness.
Q2) Suppose a genetic algorithm uses chromosomes of the form
x = abcdefgh
with a fixed length of eight genes. Each gene can be any digit between 0 and 9. Let the fitness of
individual x be calculated as:
f(x) = (a + b) – (c + d) + (e + f) – (g + h)
and let the initial population consist of four individuals with the following chromosomes:
• x₁ = 6 5 4 1 3 5 3 2
• x₂ = 8 7 1 2 6 6 0 1
• x₃ = 2 3 9 2 1 2 8 5
• x₄ = 4 1 8 5 2 0 9 4
Evaluate the fitness of each individual, showing all your workings, and arrange them in order with the
fittest first and the least fit last.
Given:
Chromosome format: x = a b c d e f g h
Fitness function:
f(x) = (a + b) – (c + d) + (e + f) – (g + h)
Chromosomes:
• x₁ = 6 5 4 1 3 5 3 2
• x₂ = 8 7 1 2 6 6 0 1
• x₃ = 2 3 9 2 1 2 8 5
• x₄ = 4 1 8 5 2 0 9 4
Step-by-step Fitness Calculations:
x₁ = 6 5 4 1 3 5 3 2
x₂ = 8 7 1 2 6 6 0 1
• (a + b) = 6 + 5 = 11
• (a + b) = 8 + 7 = 15
• (c + d) = 4 + 1 = 5
• (c + d) = 1 + 2 = 3
• (e + f) = 3 + 5 = 8
• (e + f) = 6 + 6 = 12
• (g + h) = 3 + 2 = 5
• (g + h) = 0 + 1 = 1
• f(x₁) = 11 - 5 + 8 - 5 = 9
• f(x₂) = 15 - 3 + 12 - 1 = 23
x₃ = 2 3 9 2 1 2 8 5 x₄ = 4 1 8 5 2 0 9 4
• (a + b) = 2 + 3 = 5 • (a + b) = 4 + 1 = 5
• (c + d) = 9 + 2 = 11 • (c + d) = 8 + 5 = 13
• (e + f) = 1 + 2 = 3 • (e + f) = 2 + 0 = 2
• (g + h) = 8 + 5 = 13 • (g + h) = 9 + 4 = 13
• f(x₃) = 5 - 11 + 3 - 13 = -16 • f(x₄) = 5 - 13 + 2 - 13 = -19
Fitness Results:
Chromosome Fitness
x₂ 23
x₁ 9
x₃ -16
x₄ -19
Sorted from Fittest to Least Fit:
1. x₂ = 8 7 1 2 6 6 0 1 → Fitness = 23
2. x₁ = 6 5 4 1 3 5 3 2 → Fitness = 9
3. x₃ = 2 3 9 2 1 2 8 5 → Fitness = -16
4. x₄ = 4 1 8 5 2 0 9 4 → Fitness = -19
Q3) What are the basic operators of genetic algorithms? Explain the operational procedure of GA.
Basic Operators of Genetic Algorithms (GAs):
Genetic Algorithms work based on the principles of natural evolution. The three main operators used are:
1. Selection:
• Purpose: To choose the best individuals (parents) for reproduction based on fitness.
• How it works: Fitter individuals have a higher chance of being selected.
• Common methods:
o Roulette Wheel Selection
o Tournament Selection
o Rank Selection
2. Crossover (Recombination):
• Purpose: To produce new offspring (solutions) by combining genes from two parents.
• How it works: One or more crossover points are selected, and parts of the parent chromosomes are
swapped.
• Types:
o Single-point crossover
o Two-point crossover
o Uniform crossover
Example:
Parent 1: 1010|1100
Parent 2: 1101|0011
Offspring: 10100011, 11011100
3. Mutation:
• Purpose: To introduce genetic diversity and prevent premature convergence.
• How it works: Randomly flips one or more genes in a chromosome.
• Example:
Chromosome before mutation: 10101001
After mutation at position 3: 10001001
Operational Procedure of Genetic Algorithm:
1. Initialization:
o Generate an initial population of chromosomes randomly.
2. Evaluation:
o Calculate the fitness of each individual using the fitness function.
3. Selection:
o Select individuals from the current population based on fitness to become parents.
4. Crossover:
o Apply crossover to the selected parents to produce offspring.
5. Mutation:
o Apply mutation to some offspring to maintain diversity.
6. Replacement:
o Form a new generation by selecting from parents and offspring.
7. Termination:
o Repeat steps 2–6 until a stopping condition is met:
▪ A maximum number of generations reached
▪ A satisfactory fitness level achieved
▪ No significant improvement over time
Q4) For grading system, draw membership functions for the following:
(a) Crisp grading
(b) Fuzzy grading with trapezoidal membership function
(c) Fuzzy grading with Gaussian membership function
(You can make a reasonable assumption, if any.)
Grading System - Membership Functions
Assumptions for All Types of Grading:
Let us assume student marks range from 0 to 100, and grading follows a general pattern:
Grade Marks Range
A 80 - 100
B 60 - 79
C 40 - 59
D 20 - 39
F 0 - 19
(a) Crisp Grading
Definition:
In crisp logic, each mark is strictly assigned to one grade without any overlap. It's like a cut-and-dry decision
boundary.
Membership Function: Each grade has a membership value of 1 if the marks fall within the range, else 0.
Crisp Membership Graph:
Characteristics:
• Sharp boundaries.
• No room for ambiguity.
• Simple but not human-like decision making.
(b) Fuzzy Grading – Trapezoidal Membership Function
Definition:
In fuzzy grading, marks near the grade boundaries can belong partially to two grades. The trapezoidal membership
function allows smooth transitions.
Membership Function Example (Trapezoidal):
Let’s define fuzzy regions for grade B using a trapezoid:
• Start (low support): 55
• Start (core): 60
• End (core): 75
• End (low support): 80
Characteristics:
• Handles uncertainty and smooth transitions.
• Better reflects real-world evaluation.
(c) Fuzzy Grading – Gaussian Membership Function
Definition:
Gaussian membership functions use bell-shaped curves. They are smooth and infinitely differentiable, useful for
smooth gradation.
Membership Function Example (Gaussian for Grade A):
Let’s assume:
• Mean (center of A): 90
• Standard deviation (spread): 5
Characteristics:
• Soft boundaries with natural transitions.
• Suitable for AI or adaptive systems.
• Can overlap with other Gaussian curves (e.g., Grade B near 80-85).
Conclusion and Comparison:
Aspect Crisp Grading Trapezoidal Fuzzy Grading Gaussian Fuzzy Grading
Boundaries Sharp Smooth, flat tops Smooth, curved
Human-like reasoning No Moderate High
Overlap No Yes (controlled) Yes (natural)
Complexity Low Medium High
Real-world Suitability Low Medium to High Very High
Q5) Explain the following components of fuzzy logic system:
(a) Fuzzification
(b) Rule base
(c) Defuzzification, using a real-life example.
Components of a Fuzzy Logic System
A Fuzzy Logic System (FLS) is a decision-making system that uses fuzzy logic rather than binary or crisp logic. It’s
composed of three main components:
(a) Fuzzification (3 marks)
Definition:
Fuzzification is the process of converting crisp (precise) input values into fuzzy values using membership functions.
What it does:
• Maps input values to linguistic variables like low, medium, high.
• Uses membership functions (triangular, trapezoidal, Gaussian, etc.) to determine the degree of membership.
Real-life Example:
Air Conditioner System
• Input: Room temperature = 28°C
• Linguistic variables: Cool (20–25°C), Warm (26–30°C), Hot (31–35°C)
• 28°C may belong:
o 0.6 to Warm
o 0.4 to Hot
Thus, fuzzification turns 28°C into:
{Warm: 0.6, Hot: 0.4}
(b) Rule Base (3 marks)
Definition:
The rule base consists of a set of IF-THEN rules that mimic human reasoning, written using fuzzy linguistic variables.
What it does:
• Stores expert knowledge or logic in conditional rules.
• Helps the inference engine make decisions.
Rule Syntax Example:
IF Temperature is Hot THEN Fan Speed is High
IF Temperature is Warm THEN Fan Speed is Medium
IF Temperature is Cool THEN Fan Speed is Low
Real-life Example (continued):
From the fuzzified values:
• Rule 1: IF Temp is Warm → Fan = Medium (weight 0.6)
• Rule 2: IF Temp is Hot → Fan = High (weight 0.4)
So the system considers both rules with respective strengths (weights).
(c) Defuzzification (4 marks)
Definition:
Defuzzification is the process of converting fuzzy output values into a crisp, actionable result.
What it does:
• Takes the fuzzy results from the inference process.
• Uses methods like:
o Centroid (center of gravity)
o Max-membership
o Weighted average
Real-life Example (continued):
Output fuzzy set:
• Medium Fan Speed (0.6)
• High Fan Speed (0.4)
Assume:
• Medium = 50% speed
• High = 80% speed
Summary Table:
Component Function Real-life Analogy
Fuzzification Crisp → Fuzzy 28°C → "Warm" & "Hot"
Rule Base Set of IF-THEN rules IF Warm THEN Medium Fan
Defuzzification Fuzzy → Crisp Weighted Avg → 62% Fan
Q6) Name and explain different fuzzy membership functions with diagram. Explain the basic fuzzy set properties with
suitable example.
Different Fuzzy Membership Functions and Fuzzy Set Properties
PART A: Different Fuzzy Membership Functions (5 marks)
A membership function (μ) defines how each input value in the universe of discourse is mapped to a membership
value (0 to 1) in a fuzzy set. Different types of membership functions represent different shapes and transitions.
1. Triangular Membership Function
• Shape: Triangle
• Defined by: Three points – (a, b, c)
2. Trapezoidal Membership Function
• Shape: Trapezoid
• Defined by: Four points – (a, b, c, d)
3. Gaussian Membership Function
• Shape: Bell curve
• Defined by: Mean (c) and standard deviation (σ)
4. Sigmoidal Membership Function
• Shape: S-curve
• Used for: Gradual increasing or decreasing trends
5. Singleton Membership Function
• Shape: Spike
• Used when: Precise, sharp values are needed
PART B: Fuzzy Set Properties
A fuzzy set allows partial membership of elements. The following are basic properties: