0% found this document useful (0 votes)
5 views51 pages

GSM Ga

Genetic Algorithms (GAs) utilize principles of natural selection to optimize solutions in various fields, including Generative AI. They involve processes such as initialization, evaluation, selection, crossover, mutation, and replacement to evolve solutions over generations. Key applications in Generative AI include optimizing neural network architectures, evolving latent vectors in GANs, and balancing competing goals in creative tasks.
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)
5 views51 pages

GSM Ga

Genetic Algorithms (GAs) utilize principles of natural selection to optimize solutions in various fields, including Generative AI. They involve processes such as initialization, evaluation, selection, crossover, mutation, and replacement to evolve solutions over generations. Key applications in Generative AI include optimizing neural network architectures, evolving latent vectors in GANs, and balancing competing goals in creative tasks.
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/ 51

GENETIC ALGORITHMS

Dr. G.S. Mahalakshmi


Dept. of CSE, College of Engineering, Guindy
Anna University, Chennai
GA IN GENERATIVE AI
• Genetic Algorithms (GAs) are inspired by the process of
natural selection
• Used in optimization and search problems
• When applied to Generative AI
• GAs can help evolve and optimize generative models or
outputs
• by mimicking biological evolution—selection, crossover,
mutation, and inheritance.
WORKING OF GA
• Initialization: Start with a population of possible solutions.
• Evaluation: Measure the "fitness" of each solution (how
well it performs).
• Selection: Choose the best solutions to reproduce.
• Crossover: Combine two solutions to create offspring.
• Mutation: Introduce random changes to maintain
diversity.
• Replacement: Form a new generation and repeat.
USECASES IN GENERATIVE AI
• Optimizing Neural Network Architectures
• GAs can evolve the structure (e.g., number of layers, neurons,
activation functions) of deep generative models like GANs or VAEs.
This is called Neuroevolution.
• Evolving Latent Vectors in GANs
• Instead of sampling random latent vectors for image generation,
GAs can evolve a population of latent vectors to generate outputs
with desired features (e.g., realistic faces, specific styles).
• Symbolic or Rule-based Generation
• In text, music, or design generation, GAs can optimize combinations
of symbols or rules to produce novel and high-quality content.
• Example: Generating melodies, where fitness = harmony + novelty.
USECASES IN GENERATIVE AI
• Multi-objective Optimization in Creative Tasks
• GAs can balance competing goals (e.g., novelty vs.
realism) in generating art, design, or stories.
• Interactive Evolutionary Systems
• Users rate generated content (e.g., images, designs),
and GA evolves the next generation based on human
preference (used in co-creative tools).
• Example: GA for GAN Latent Space
EXAMPLE
• Goal: Generate images of flowers with maximum color
diversity.
1. Population: 100 random latent vectors.
2. Fitness: Diversity score of the generated image.
3. Select top 20, apply crossover & mutation.
4. Iterate 50 generations.

• Outcome: Latent vectors that consistently generate


diverse, colorful flowers.
GA WORKFLOW
• Initialize a random
population
• Evaluate fitness
• Select parents
• Apply crossover
• Apply mutation
• Create new
generation
• Repeat until
stopping criteria
are met
BIOLOGY BEHIND
• Each cell of a living organism contains chromosomes – strings
of DNA
• Each chromosome contains a set of genes – blocks of DNA
• Each genes encodes a particular pattern – trait
• Possible settings of traits – alleles
• The unique position of gene in chromosome – locus
• Complete set of genetic material – genome
• A collection of genes – genotype
• A collection of aspects (like eye color) – phenotype
• Reproduction involves recombination of genes from parents
• The fitness of an organism is how much it can reproduce
before it dies
GENOTYPE REPRESENTATION
• Binary

• Real-valued

• Integer

• Permutatio
n
GA REQUIREMENTS
• Objective function - Genetic representation - Genetic operator
• Process
• Each individual is assessed via fitness function – higher
fitness better the solution
• Based on their fitness, parents are selected to reproduce
offspring for a new generation
• Fitter individuals have more chance to reproduce
• New generation has same size as old generation – old gen
dies
• Offspring has combination of properties of two parents
• If well designed, population converges to optimal solution
POPULATION REQUIREMENTS
• Population initialization
• Random initialization
• Heuristic initialisation
• Population models
• Steady state
• Generational
OUTLINE OF GA
1. Algorithm begins by creating a random initial population.
2. Create a sequence of new populations. At each step, the algorithm uses the individuals in the
current generation to create the next population. To create the new population, the algorithm
performs the following steps:
1. Scores each member of the current population by computing its fitness value. These
values are called the raw fitness scores.
2. Scales the raw fitness scores to convert them into a more usable range of values. These
scaled values are called expectation values.
3. Selects members, called parents, based on their expectation.
4. Some of the individuals in the current population that have lower fitness are chosen
as elite. These elite individuals are passed to the next population.
5. Produces children from the parents. Children are produced either by making random
changes to a single parent—mutation—or by combining the vector entries of a pair of
parents—crossover.
6. Replaces the current population with the children to form the next generation.
3. The algorithm stops when one of the stopping criteria is met
4. The algorithm takes modified steps for linear and integer constraints.
5. The algorithm is further modified for nonlinear constraints.
KEY CONCEPTS OF GA
• Chromosome
• A possible solution (usually a string or array)
• Gene
• A part of a chromosome (e.g., a number or character)
• Fitness Function
• A function to evaluate how good a solution is
• Population
• A group of chromosomes
• Generation
• One cycle of selection, crossover, and mutation
• Individual
• An individual is any point to which you can apply the fitness
function. The value of the fitness function for an individual is
POPULATION
• an array of individuals.
• Ex. if size of population is 100, number of variables in the
fitness function is 3, you represent the population by a 100-
by-3 matrix.
• Sampling without Replacement
• Sampling with Replacement
• After selecting an individual, return them to population before
the next draw. So, same individual is selected multiple times
• Same individual appears more than once in the population.
• At each iteration, GA performs a series of computations on
the current population to produce a new population. Each
successive population is called a new generation.
• Suppose your population is [A, B, C], and you sample 3 times with replacement. A
possible sample could be [A, A, B]
POPULATION - DIVERSITY
• It's possible that the same solution (individual) appears
more than once in the population if:
• It was selected multiple times for reproduction.
• It survived multiple generations.
• There’s a lack of diversity or poor mutation/crossover
parameters.
• Diversity
• Diversity refers to the average distance between
individuals in a population.
• A population has high diversity if the average distance
is large; otherwise it has low diversity.
POPULATION MIGRATION
• Migration options specify how individuals move between
subpopulations.
• Migration occurs if PopulationSize is set as a vector of length > 1.
• When migration occurs, the best individuals from one
subpopulation replace the worst individuals in another
subpopulation.
• Individuals that migrate from one subpopulation to another are
copied. They are not removed from the source subpopulation.
• Migration Direction, Migration Interval, Migration
Fraction
CREATING THE NEXT
GENERATION
• At each step, the genetic algorithm uses the current population to
create the children that make up the next generation.
• The algorithm selects a group of individuals in the current
population, called parents, who contribute their genes—the entries
of their vectors—to their children.
• The algorithm usually selects individuals that have better fitness
values as parents.
SELECTION
• The process that determines which solutions are to be
preserved and allowed to reproduce and which ones
deserve to die out.
• The primary objective of the selection operator is to
emphasize the good solutions and eliminate the bad
solutions in a population while keeping the population
size constant.

• “Select the best, discard the rest”


SELECTION OPERATOR
• Identify the good solutions in a population
• Make multiple copies of the good solutions
• Eliminate bad solutions from the population so that
multiple copies of good solutions can be placed I
• n the population
• Now how to identify the good solutions?
• Fitness Function
FITNESS VALUE
• Fitness Values
• value of the fitness function for that individual.
• quantifies the optimality of a solution.
• The value is used to rank a particular solution against all the
other solutions
• A fitness value is assigned to each solution depending on
how close it is actually to the optimal solution of the problem
• Parents and Children
• To create next generation, GA selects certain individuals in
the current population, called parents, and uses them to
create individuals in next generation, called children.
• Typically, the algorithm is more likely to select parents that
have better fitness values.
SELECTION METHODS
• Uniform Selection
• Roulette Wheel Selection
• Tournament Selection
• Rank Selection
• Proportionate Selection
• Steady State Selection
• Boltzmann Selection
BOLTZMANN SELECTION
TOURNAMENT SELECTION
• Several tournaments
are played among a
few individuals.
• Individuals are chosen
at random from the
population.
• Winner of each
tournament is selected
for next generation.
• Selection pressure can
be adjusted by
changing the
tournament size.
• Weak individuals have
a smaller chance to be
selected if tournament
size is large.
PROPORTIONATE SELECTION
• Parents are selected according to their fitness values

• The better the


chromosomes,
more chances
to get
selected
ROULETTE WHEEL
SELECTION
• The basic part of the selection process is to stochastically select from one
generation to create the basis of the next generation. The fittest individuals
have a greater chance of survival than weaker ones. Weaker individuals
are not without a chance.
RANK SELECTION
STEADY STATE SELECTION
• In this method, a few good chromosomes are used for creating
new offspring in every iteration. Then some bad chromosomes
are removed and the new offspring is placed in their places. The
rest of population migrates to the next generation without
going through the selection process.
CROSSOVER & MUTATION

• Crossover: Combine genes from parents (e.g., one-point,


two-point, uniform)
• Mutation: Introduce random gene changes to maintain
diversity
• GA creates three types of children :
• Elite children
• Crossover children
• Mutation children
HOW TO IMPLEMENT
CROSSOVER

• The crossover operator is used to create new solutions from the existing
solutions available in the mating pool after applying selection operator.
This operator exchanges the gene information between the solutions in
the mating pool.
ENCODING FOR CROSSOVER
• The process of representing a solution in the form of a string that conveys
the necessary information. Just as in a chromosome, each gene controls a
particular characteristic of the individual, similarly, each bit in the string
represents a characteristic of the solution. Most common method of
encoding is binary coded. Chromosomes are strings of 1 and 0 and each
position in the chromosome represents a particular characteristic of the
problem.
• Chromosomes
are strings of 1
and 0 and each
position in the
chromosome
represents a
particular
characteristic
of the problem.
CROSSOVER OPERATOR
• The most popular crossover
selects any two solutions
strings randomly from the
mating pool and some
portion of the strings is
exchanged between the
strings.
• The selection point is
selected randomly
• A probability of crossover is
also introduced in order to
give freedom to an
individual solution string to
determine whether the
solution would go for
crossover or not.
BINARY CROSSOVER
TYPES OF CROSSOVER
• Single point crossover
• Two point crossover - Two random points are chosen
• Multi point crossover
• Uniform crossover
• Matrix crossover
• Inversion
• Order 1 crossover
• Deletion
• Deletion and duplication, Deletion and regeneration
SINGLE POINT CROSSOVER

• A random
point is chosen
on individual
chromosome
and genetic
material is
exchanged at
this point
TWO-POINT CROSSOVER
• Two random points
are chosen on
individual
chromosomes and
genetic material is
exchanged at this
point
• Avoids cases where
genes at the
beginning and end
of a chromosome
are always split
• Even number of cross
sites
• Odd number of cross
sites

MULTIPOINT
CROSSOVER
UNIFORM CROSSOVER
MATRIX CROSSOVER
CROSSOVER - INVERSION
ORDER 1 CROSSOVER
CROSSOVER - DELETION
MUTATION OPERATOR
• Mutation is the occasional introduction of new features in
to the solution strings of the population pool to maintain
diversity in the population.
BINARY MUTATION
• Mutation operator changes a 1 to 0 or vise versa, with a
mutation probability
• The mutation probability is generally kept low for steady
convergence.
OTHER MUTATION
OPERATORS
• Binary
• Flip bitwise
• Random
resetting
• Swap
• Scramble
• Inversion
GA SURVIVOR SELECTION
• Elitist selection:
• Choose only the most fit members of each
generation.
• Cutoff selection:
• Select only those that are above a certain cutoff for
the target function.
• Age based Selection
• Fitness based Selection
ELITISM
• Crossover and mutation may destroy the best solution of
the population pool
• Elitism is the preservation of few best solutions of the
population pool
• Elitism is defined in percentage or in number
TYPES OF CHILDREN
Elite children are individuals in
current generation with best
fitness values. These
individuals automatically
survive to next generation.
Crossover children are
created by combining the
vectors of a pair of
parents.
Mutation children are
created by introducing
random changes, or
mutations, to a single
AGE BASED SELECTION
FITNESS BASED SELECTION
OVERALL PROCESS OF GA
STOPPING CRITERIA
•MaxGenerations —maximum number of iterations
•MaxTime —maximum time
•FitnessLimit —if the best fitness value is < = value
of FitnessLimit.
•MaxStallGenerations —if the avg. relative change in best
fitness function value over MaxStallGenerations is < =
FunctionTolerance.
•MaxStallTime —if there is no improvement in the best
fitness value for an interval of time
•FunctionTolerance —average relative change in best fitness
function value over MaxStallGenerations is

You might also like