0% found this document useful (0 votes)
7 views15 pages

Implementation of Genetic Algos

Uploaded by

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

Implementation of Genetic Algos

Uploaded by

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

Genetic Algorithms: An

Introduction and Python


Implementation
By
Dr. Inam Ullah Khan
Introduction to Genetic Algorithms

What are Genetic Algorithms?

•Genetic Algorithms (GAs) are a type of


optimization algorithm inspired by the
process of natural selection.
•They are used to find approximate
solutions to complex problems by evolving
a population of candidate solutions over
several generations.
Key Concepts:
•Population: A group of potential
solutions.

•Fitness Function: A way to evaluate how


good each solution is.

•Selection: Choosing the best solutions for


reproduction.

•Crossover: Combining parts of two


solutions to create a new one.

•Mutation: Introducing random changes to


create diversity.
How Genetic Algorithms
Work

Step-by-Step Process:

1.Initialization: Start with a random population.


2.Evaluation: Calculate the fitness of each individual.
3.Selection: Select the fittest individuals for reproduction.
4.Crossover: Generate new offspring by combining genes of parents.
5.Mutation: Apply random changes to offspring.
6.Replacement: Form a new population from parents and offspring.
7.Termination: Repeat until the population converges to a solution.

•Applications:

•Genetic Algorithms are used in various fields such as


• machine learning, engineering design, scheduling, and more.
Example Problem
•Problem Statement:
•Minimize the function f(x)=x2f(x) = x^2f(x)=x2.
•The goal is to find the value of xxx that results in the lowest
possible value of f(x)f(x)f(x).

•Why Use a Genetic Algorithm?


•The function is simple, but GAs can be applied to much more
complex,
non-linear, and high-dimensional problems where traditional
methods might fail.
Objective Function

•Explanation:

• This function defines the problem we want to minimize.


In this case, we are simply trying to find the xxx that
makes x2x^2x2 as small as possible.
Generate Initial Population

•Explanation:

A random initial population is generated within a specified


range. This is the starting point of the GA.
Evaluate Fitness

Explanation:

Fitness scores are calculated for each individual based on


how well they solve the problem (i.e., how small their
objective function value is).
Selection

Explanation:

The fittest individuals are selected as parents for the next


generation. These individuals are likely to pass their good
genes on to the offspring.
Crossover

Explanation:

New offspring are generated by combining the genetic


information from two parents. This simulates the biological
crossover process.
Mutation

Explanation:

Mutation introduces random changes in the offspring to


maintain diversity within the population. This prevents the
algorithm from getting stuck in local minima.
GA Main Function

Explanation:
•This function brings together all the components of the GA, running it
over multiple generations to find an optimal solution.
Running the Genetic
Algorithm

Explanation:
•The algorithm is run with specific parameters, and the best solution found is
printed. This is the result of the GA's optimization process.
Conclusion
•Summary:
•Genetic Algorithms are powerful optimization tools inspired by natural
selection.
•They are particularly useful for complex, non-linear, and high-dimensional
problems where traditional methods struggle.
•The example provided demonstrates a basic implementation of GA in Python
to minimize a quadratic function.

•Further Exploration:
•Experiment with different objective functions, population sizes, crossover rates,
and mutation rates.
•Apply Genetic Algorithms to real-world optimization problems in fields like
machine
learning, engineering, and finance.
1
Thank you 8

You might also like