Genetic Algorithm
Genetic Algorithm
• Let’s take a hypothetical situation where, you are head of a country, and in order to keep your city
safe from bad things, you implement a policy like this. • You select all the good people, and ask them
to extend their generation by having their children. • This repeats for a few generations.
• You will notice that now you have an entire population of good people.
• So the basic idea was that we changed the input (i.e. population) such that we get better output
(i.e. better
country).
Biological Inspiration
• And finally, these off-springs replace the bad people from the population and this
process repeats.
• This is how genetic algorithm actually works, which basically tries to mimic the
human evolution to some extent.
What is a Genetic Algorithm?
• So to formalize a definition of a genetic algorithm, we can say that it is an optimization technique,
which tries to find out such values of input so that we get the best output values or results.
• The working of a genetic algorithm is also derived from biology, which is as shown in the image
below.
Initialization
• To solve this problem using genetic algorithm, our first step would be defining our population. So
our population will contain individuals, each having their own set of chromosomes.
• We know that, chromosomes are binary strings, where for this problem 1 would mean that the
following item is taken and 0 meaning that it is dropped.
Fitness Function
• Similarly for A2 chromosome [001110],
So, for this problem, our chromosome will be considered as more fit when it contains more survival
points.
Therefore chromosome 1 is more fit than chromosome 2.
Fitness Function
• There are two main categories of methods for using fitness in order to support selection
1. Deterministic methods
• Fitness function is evaluated using fixed set of criteria
• This approach ensures that each solution is evaluated consistently and objectively. • Involve
for example the selection of n most fit individuals in a population for recombination.
• They are generally discredited because they tend to develop a population that reaches the local
maximum and stops evolving
2. Stochastic Method
• In the stochastic method, the fitness function incorporates some element of randomness or
probabilistic evaluation.
• This approach allows for more flexibility in evaluating solutions and can capture a wider
range of possible solutions.
reasons:
method. It does not require complex computations or parameter tuning. The selection process can
be efficiently performed by generating a random number and traversing the population to find the
selected individual based on the calculated probabilities. This simplicity and efficiency make it a
popular choice for genetic algorithm implementations.
4. Reproduction proportionality: Since the selection probabilities are directly proportional to the
fitness values, the roulette wheel selection method ensures that the reproductive contribution of
each individual is proportional to its fitness. This helps in maintaining the genetic
Selection
• Now, we can select fit chromosomes from our population which can mate and create their off
springs.
• General thought is that we should select the fit chromosomes and allow them to produce off
springs. But that would lead to chromosomes that are more close to one another in a few next
generation, and therefore less diversity.
• Therefore, we generally use Roulette Wheel Selection method.
Roulette Wheel Selection
• Consider a wheel, and let’s divide that into m divisions, where m is the number of
chromosomes in our populations. The area occupied by each chromosome will be
proportional to its fitness value.
Crossover
If you take two
crossover point, then it will called as multi point crossover which is as shown below.
Mutation
• Now if you think in the biological sense, are the children produced have the same
traits as their parents? The answer is NO.
• During their growth, there is some change in the genes of children which makes
them different from its parents.
• This process is known as mutation, which may be defined as a random tweak in
the chromosome, which also promotes the idea of diversity in the population.
• So basically there are different termination conditions, which are listed below:
• There is no improvement in the population for over x iterations.
• We have already predefined an absolute number of generation for our algorithm.
• When our fitness function has reached a predefined value.
Example
• Imagine a population of birds trying to find the best way to build their nests. The
birds have different characteristics, such as beak size, wing shape, and feather
color, which can affect their ability to build a successful nest.
• The goal is to find the best combination of these characteristics that will result in
the most effective nest-building behavior.
The first step in a genetic algorithm is the evaluation of the fitness of each
individual in the population. In our example, the fitness of a bird can be
determined by how well it can build a nest. Birds with better nest-building skills
will have a higher fitness score.
Example
• The next step is the selection process, where individuals with higher fitness
scores have a higher chance of reproducing. This mimics natural selection, where
individuals with advantageous traits are more likely to survive and pass on their
genes to the next generation.
•
5. Mutation:
Introduce random changes to the newly generated alignments to maintain
genetic diversity in the population. These changes can include insertions,
deletions,
Application of Genetic Algorithm in Feature
Selection
• 1. Classification: Genetic algorithms can be used to select a subset of features
that are most relevant for a particular classification task. By evaluating the fitness
of different feature subsets based on their classification performance, genetic
algorithms can efficiently search for an optimal subset of features.
2. Regression: Genetic algorithms can also be applied to feature selection in
regression tasks. By considering the relationship between the selected features
and the target variable, genetic algorithms can identify the most informative
features for accurate regression modeling.
• Is there any better way to deal with this kind of situations? Actually one of the most
advanced algorithms for feature selection is genetic algorithm.
• The method here is completely same as the one we did with the knapsack problem.
• We will again start with the population of chromosome, where each chromosome will be
binary string. 1 will denote “inclusion” of feature in model and 0 will denote “exclusion”
of feature in the model.
Feature Selection
• And another difference would be that the fitness function would be
changed. The fitness function here will be our accuracy metric of the
competition. The more accurate our set of chromosome in predicting
value, the more fit it will be.
Advantages of GAs
Examples not suitable for Genetic Algorithm
1. Continuous and smooth search space:
It is suitable for the problems in discrete space where there are distinct solutions.
2. Problems with small number of variables:
GA are more effective when dealing with problems that have large number of
variables.
3. Time-Sensitive problems:
GAs are computationally expensive and may require a significant amount of time to
converge to an optimal solution.
References
1. Biologically Inspired Optimization Methods: An Introduction by M.
Wahde ,Chalmers University of Technology, Sweden