0% found this document useful (0 votes)
35 views9 pages

ML Unit Iv Part Ii

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views9 pages

ML Unit Iv Part Ii

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Evolutionary Learning is a type of machine learning inspired by natural selection.

It uses
evolutionary algorithms (EAs) to optimize models or solutions by simulating the process of
evolution. These algorithms work by evolving a population of candidate solutions over several
generations using operations like selection, crossover, and mutation.

Key Concepts:

1. Population: A set of candidate solutions (models or parameters).


2. Fitness Function: A measure of how good a candidate solution is.
3. Selection: The process of choosing the best solutions based on their fitness.
4. Crossover (Recombination): Combining parts of two solutions to create a new one.
5. Mutation: Randomly altering parts of a solution to introduce diversity.

Steps in Evolutionary Learning:

1. Initialize: Generate an initial population randomly.


2. Evaluate: Calculate the fitness of each individual in the population.
3. Select: Choose the best-performing individuals.
4. Reproduce: Apply crossover and mutation to create new individuals.
5. Replace: Form a new population and repeat the process.

Applications:

 Optimization problems (e.g., scheduling, routing).


 Feature selection in machine learning.
 Neural network training (Neuroevolution).
 Game strategy development.

Advantages:

 Can handle complex, non-linear problems.


 Does not require gradient information (useful for non-differentiable problems).
 Can escape local minima.

Disadvantages:

 Computationally expensive.
 May require careful tuning of parameters (mutation rate, population size, etc.).

Genetic Algorithm in Machine Learning


A genetic algorithm is an adaptive heuristic search algorithm inspired by "Darwin's theory of
evolution in Nature." It is used to solve optimization problems in machine learning. It is one of
the important algorithms as it helps solve complex problems that would take a long time to solve.
Genetic Algorithms are being widely used in different real-world applications, for
example, Designing electronic circuits, code-breaking, image processing, and artificial
creativity.

What is a Genetic Algorithm?

Basic Terminologies:

o Population: Population is the subset of all possible or probable solutions, which can
solve the given problem.
o Chromosomes: A chromosome is one of the solutions in the population for the given
problem, and the collection of gene generate a chromosome.
o Gene: A chromosome is divided into a different gene, or it is an element of the
chromosome.
o Allele: Allele is the value provided to the gene within a particular chromosome.
o Fitness Function: The fitness function is used to determine the individual's fitness level
in the population. It means the ability of an individual to compete with other individuals.
In every iteration, individuals are evaluated based on their fitness function.
o Genetic Operators: In a genetic algorithm, the best individual mate to regenerate
offspring better than parents. Here genetic operators play a role in changing the genetic
composition of the next generation.
o Selection
After calculating the fitness of every existent in the population, a selection process is used to
determine which of the individualities in the population will get to reproduce and produce the
seed that will form the coming generation.

Types of selection styles available

o Roulette wheel selection


o Event selection
o Rank- grounded selection
So, now we can define a genetic algorithm as a heuristic search algorithm to solve optimization
problems. It is a subset of evolutionary algorithms, which is used in computing. A genetic
algorithm uses genetic and natural selection concepts to solve optimization problems.

How Genetic Algorithm Work?


The genetic algorithm works on the evolutionary generational cycle to generate high-quality
solutions. These algorithms use different operations that either enhance or replace the population
to give an improved fit solution.
It basically involves five phases to solve the complex optimization problems, which are given as
below:

o Initialization
o Fitness Assignment
o Selection
o Reproduction
o Termination

1. Initialization
The process of a genetic algorithm starts by generating the set of individuals, which is called
population. Here each individual is the solution for the given problem. An individual contains or
is characterized by a set of parameters called Genes. Genes are combined into a string and
generate chromosomes, which is the solution to the problem. One of the most popular techniques
for initialization is the use of random binary strings.

2. Fitness Assignment

Fitness function is used to determine how fit an individual is? It means the ability of an
individual to compete with other individuals. In every iteration, individuals are evaluated based
on their fitness function. The fitness function provides a fitness score to each individual. This
score further determines the probability of being selected for reproduction. The high the fitness
score, the more chances of getting selected for reproduction.

3. Selection

The selection phase involves the selection of individuals for the reproduction of offspring. All
the selected individuals are then arranged in a pair of two to increase reproduction. Then these
individuals transfer their genes to the next generation.

There are three types of Selection methods available, which are:

o Roulette wheel selection


o Tournament selection
o Rank-based selection

4. Reproduction

After the selection process, the creation of a child occurs in the reproduction step. In this step,
the genetic algorithm uses two variation operators that are applied to the parent population. The
two operators involved in the reproduction phase are given below:

o Crossover: The crossover plays a most significant role in the reproduction phase of the
genetic algorithm. In this process, a crossover point is selected at random within the
genes. Then the crossover operator swaps genetic information of two parents from the
current generation to produce a new individual representing the offspring.
The genes of parents are exchanged among themselves until the crossover point is met. These
newly generated offspring are added to the population. This process is also called or crossover.
Types of crossover styles available:

o One point crossover


o Two-point crossover
o Livery crossover
o Inheritable Algorithms crossover
o Mutation
The mutation operator inserts random genes in the offspring (new child) to maintain the
diversity in the population. It can be done by flipping some bits in the chromosomes.
Mutation helps in solving the issue of premature convergence and enhances
diversification. The below image shows the mutation process:
Types of mutation styles available,
o Flip bit mutation
o Gaussian mutation
o Exchange/Swap mutation

5. Termination
After the reproduction phase, a stopping criterion is applied as a base for termination. The
algorithm terminates after the threshold fitness solution is reached. It will identify the final
solution as the best solution in the population.

General Workflow of a Simple Genetic Algorithm


Advantages of Genetic Algorithm

o The parallel capabilities of genetic algorithms are best.


o It helps in optimizing various problems such as discrete functions, multi-objective
problems, and continuous functions.
o It provides a solution for a problem that improves over time.
o A genetic algorithm does not need derivative information.

Limitations of Genetic Algorithms

o Genetic algorithms are not efficient algorithms for solving simple problems.
o It does not guarantee the quality of the final solution to a problem.
o Repetitive calculation of fitness values may generate some computational challenges.
Difference between Genetic Algorithms and Traditional Algorithms

o A search space is the set of all possible solutions to the problem. In the traditional
algorithm, only one set of solutions is maintained, whereas, in a genetic algorithm,
several sets of solutions in search space can be used.
o Traditional algorithms need more information in order to perform a search, whereas
genetic algorithms need only one objective function to calculate the fitness of an
individual.
o Traditional Algorithms cannot work parallelly, whereas genetic Algorithms can work
parallelly (calculating the fitness of the individualities are independent).
o One big difference in genetic Algorithms is that rather of operating directly on seeker
results, inheritable algorithms operate on their representations (or rendering), frequently
appertained to as chromosomes.
o One of the big differences between traditional algorithm and genetic algorithm is that it
does not directly operate on candidate solutions.
o Traditional Algorithms can only generate one result in the end, whereas Genetic
Algorithms can generate multiple optimal results from different generations.
o The traditional algorithm is not more likely to generate optimal results, whereas Genetic
algorithms do not guarantee to generate optimal global results, but also there is a great
possibility of getting the optimal result for a problem as it uses genetic operators such as
Crossover and Mutation.
o Traditional algorithms are deterministic in nature, whereas Genetic algorithms are
probabilistic and stochastic in nature.

Genetic Operators

Genetic algorithms rely on three main operators to evolve the population:

1. Selection
o Purpose: Chooses the fittest individuals to pass their genes to the next generation.
o Techniques:
 Roulette Wheel Selection: Probability-based, proportional to fitness.
 Tournament Selection: Selects the best individual from a random subset.
 Rank Selection: Ranks individuals and assigns selection probability based
on rank.
2. Crossover (Recombination)
o Purpose: Combines genetic information from two parents to produce offspring.
o Types:
 Single-point Crossover: A single point is chosen, and parts of
chromosomes are swapped.
 Two-point Crossover: Two points are chosen, and the segment between
them is swapped.
 Uniform Crossover: Genes are randomly swapped based on a fixed
probability.
3. Mutation
o Purpose: Introduces random changes in chromosomes to maintain diversity.
o Types:
 Bit Flip Mutation: Flips a random bit in a binary chromosome.
 Swap Mutation: Swaps two genes in a chromosome.
 Gaussian Mutation: Adds a small random value to numerical genes.

General Examples for Genetic Algorithm Operators

1. Selection Methods:

 Roulette Wheel Selection:


Imagine a wheel divided into sections proportional to individuals' fitness scores. A
solution with 70% fitness will take 70% of the wheel space. Higher fitness means a
higher chance of selection.
Example: Selecting parents based on their performance in a sales competition, where
better sales lead to higher probability.
 Tournament Selection:
Selects a random subset of individuals and picks the best among them.
Example: Organizing a small coding competition within a larger group and choosing the
winner for further training.
 Rank Selection:
Individuals are ranked based on fitness, and the selection probability is based on rank, not
absolute fitness.
Example: Employees are ranked by performance, and promotions are based on their rank
rather than exact performance scores.

2. Crossover Types:

 Single-Point Crossover:
Two parent strings split at a single point, and parts are swapped.
Example:
o Parent 1: 1010|1101
o Parent 2: 0110|0011
o Offspring: 10100011 and 01101101
 Two-Point Crossover:
Two points are chosen, and the section between them is swapped.
Example:
o Parent 1: 101|011|01
o Parent 2: 110|000|11
o Offspring: 10100011 and 11001101
 Uniform Crossover:
Each gene is swapped with a fixed probability.
Example:
o Parent 1: 101011
o Parent 2: 110100
o Offspring: 111001 (randomly chosen from both parents)

3. Mutation Types:

Bit Flip Mutation:


A random bit in the chromosome is flipped (0 to 1 or 1 to 0).
Example:
 Original: 101011 → Mutated: 101111

Swap Mutation:
Two positions in the chromosome are swapped.
Example:

 Original: ABCDE → Mutated: ABDCE

Gaussian Mutation:
A small random value is added to numerical genes.
Example:

 Original: 5.4, 2.3 → Mutated: 5.5, 2.1 (random Gaussian noise applied)

Using Genetic Algorithms (GAs)


To use a genetic algorithm effectively, these steps need to be followed:
1. Define the Problem
Clearly outline the problem you want to solve, including constraints and objectives.
 Example: Find the optimal schedule for employees in a week.
2. Encode the Solution (Chromosome Representation)
Decide how to represent a solution as a chromosome (binary, integer, real-valued, or
permutation).
 Example: For a scheduling problem, each chromosome could represent an employee's
shift assignments as a list of integers.
3. Design the Fitness Function
Create a function that evaluates how good each solution is. The fitness function should reflect the
objective of the problem.
 Example: In a scheduling problem, the fitness function could minimize the total number
of conflicts or maximize employee satisfaction.
4. Implement Genetic Operators
Use the following genetic operators to evolve the population:
 Selection: Choose the fittest individuals for reproduction.
o Example: Use tournament selection or roulette wheel selection.
 Crossover (Recombination): Combine two parent solutions to create offspring.
o Example: Perform a single-point crossover on binary chromosomes.
 Mutation: Introduce random changes to maintain diversity.
o Example: Flip a random bit or swap two genes.

5. Set Parameters
Define important parameters for the genetic algorithm:
 Population size
 Crossover rate
 Mutation rate
 Number of generations

6. Run the Algorithm


Initialize a random population and iterate through the genetic algorithm cycle:
1. Evaluate fitness of each individual.
2. Select parents based on fitness.
3. Apply crossover and mutation to generate offspring.
4. Replace the population with new individuals.
5. Repeat until a termination condition is met (e.g., reaching a set number of generations or
finding a satisfactory solution).

Example: Solving a Simple Optimization Problem


Problem: Maximize the function (x) = x2 for x in the range [0, 31].

Steps:

1. Encode: Represent xxx as a 5-bit binary string.


2. Fitness Function: f (x) = x2.
3. Selection: Use roulette wheel selection.
4. Crossover: Single-point crossover with a probability of 0.7.
5. Mutation: Flip a bit with a probability of 0.01.
6. Run: Iterate for 100 generations.

Applications of Using GAs


 Optimization: Logistics, resource allocation, scheduling.
 Machine Learning: Feature selection, neural network optimization.
 Engineering: Design and parameter optimization.
 Game Development: AI behavior and strategy optimization.

You might also like