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

ML U4 Notes

c dv ccxc

Uploaded by

Shrenik Pittala
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)
13 views15 pages

ML U4 Notes

c dv ccxc

Uploaded by

Shrenik Pittala
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/ 15

Multi Dimentional Scaling

MDS (Multi-Dimensional Scaling) is a dimensionality reduction algorithm. Its primary goal is to transform
high-dimensional data into a lower-dimensional space (like 2D or 3D) while preserving the distances (or
similarities) between the points. It's often used for visualization or data exploration.
Explanation of Elitism, Tournaments, and Niching in Genetic Algorithms

Genetic Algorithms (GAs) are optimization techniques inspired by natural selection. These three
concepts play critical roles in maintaining diversity, selecting the best solutions, and avoiding premature
convergence.

1. Elitism

• Definition: Elitism is a strategy in Genetic Algorithms where the best individuals (solutions) from
the current generation are preserved and directly passed to the next generation without
modification.

• Purpose:

o Ensures that the best solutions are not lost during the evolution process.
o Helps maintain the quality of the population.

2. Tournaments (Tournament Selection)

• Definition: A selection method where a subset of individuals is randomly chosen from the
population, and the best individual among this subset (based on fitness) is selected as a parent
for the next generation.

• Purpose:

o Increases the chances of selecting high-quality individuals.

o Balances between exploitation (selecting the best) and exploration (allowing weaker
individuals to occasionally reproduce).

3. Niching

• Definition: A technique used in Genetic Algorithms to maintain diversity by encouraging the


population to explore different areas of the search space. It reduces competition among
individuals that are too similar.

• Purpose:

o Prevents the population from converging prematurely to a single solution.

o Encourages exploration of multiple optima in multi-modal problems (problems with


multiple peaks or valleys in the solution space).

Application of Genetic Algorithm


Map Coloring
Map Coloring is a problem in graph theory where the goal is to assign colors to regions on a map such
that no two adjacent regions have the same color, using the minimum number of colors. This is also
known as the Graph Coloring Problem.

A Genetic Algorithm (GA) can be applied to solve this problem by treating it as an optimization problem.

How the Genetic Algorithm Works for Map Coloring

1. Encoding the Solution

• Each individual in the population represents a possible coloring of the map.

• Encoding is done using chromosomes, where:

o Each gene represents a region (or node in a graph).

o Each value in the gene corresponds to a color assigned to that region.

• Example:
o For a map with 4 regions (A, B, C, D) and 3 possible colors, a chromosome could look
like: [1,2,1,3][1, 2, 1, 3]

▪ Here, region A is colored 1, region B is colored 2, region C is colored 1, and


region D is colored 3.

2. Fitness Function

• The fitness function evaluates how "good" a solution is.

• For map coloring:

o Count the number of violations (i.e., pairs of adjacent regions with the same color).

o The fewer the violations, the better the fitness.

• Example:

o If regions A and B are adjacent and both have color 1, it is a violation.

o Fitness = Total number of regions−Number of violations\text{Total number of regions} -


\text{Number of violations}.

3. Initialization

• Randomly generate an initial population of possible colorings.

• Each individual in the population represents a potential solution.

4. Selection

• Use a selection method (e.g., tournament selection) to choose parents based on fitness.

• Higher fitness solutions are more likely to be selected.

5. Crossover

• Combine two parent solutions to produce offspring.

• Example:

o Parent 1: [1,2,1,3][1, 2, 1, 3]

o Parent 2: [2,1,3,1][2, 1, 3, 1]

o Crossover Point: 2

o Offspring: [1,2,3,1][1, 2, 3, 1]
6. Mutation

• Introduce random changes to a small number of genes to maintain diversity.

• Example:

o Original: [1,2,3,1][1, 2, 3, 1]

o Mutated: [1,2,3,2][1, 2, 3, 2]

o Here, the last region's color was changed from 1 to 2.

7. Termination

• The algorithm stops when:

o A solution with no violations is found.

o A maximum number of generations is reached.

Steps of Genetic Algorithm for Map Coloring

1. Input:

o Number of regions on the map.

o Adjacency information (which regions are adjacent).

o Maximum number of colors allowed.

2. Generate Initial Population:

o Create random color assignments for each individual.

3. Evaluate Fitness:

o Check how many adjacent regions violate the coloring rule.

4. Selection:

o Select the best individuals based on fitness.

5. Crossover:

o Create new individuals by combining parts of two parents.

6. Mutation:

o Randomly modify genes to explore new solutions.

7. Repeat:
o Continue the process for a fixed number of generations or until an optimal solution is
found.

Example

Map:

Regions: A,B,C,DA, B, C, D
Adjacency:

• AA is adjacent to BB and CC.

• BB is adjacent to AA and DD.

• CC is adjacent to AA and DD.

• DD is adjacent to BB and CC.

Steps:

1. Initial Population:

o Individual 1: [1,2,1,3][1, 2, 1, 3]

o Individual 2: [2,1,3,2][2, 1, 3, 2]

2. Fitness Evaluation:

o Individual 1: No violations → Fitness = 4.

o Individual 2: One violation (BB and DD both have color 2) → Fitness = 3.

3. Selection:

o Select Individual 1 (higher fitness).

4. Crossover:

o Combine Individual 1 and Individual 2:

▪ Offspring: [1,2,3,2][1, 2, 3, 2].

5. Mutation:

o Change the color of Region DD in the offspring:

▪ Mutated: [1,2,3,1][1, 2, 3, 1].

6. Repeat until no violations exist.

Advantages of Using GA for Map Coloring


• Efficient for complex maps with many regions.

• Does not require prior knowledge of the problem space.

• Finds approximate solutions quickly for large-scale problems.

Limitations

• May not guarantee the optimal solution.

• Can converge prematurely if diversity is not maintained.

• Performance depends on parameter tuning (e.g., population size, mutation rate).

Real-World Applications

• Geographical Maps: Efficiently coloring political maps.

• Scheduling Problems: Assigning tasks to time slots (similar to coloring).

• Frequency Allocation: Assigning frequencies in wireless networks to avoid interference.

The Knapsack Problem


Knapsack Problem in Genetic Algorithm

The Knapsack Problem is a classic optimization problem where you need to maximize the total value of
items that can be placed in a knapsack, without exceeding its weight capacity.

Problem Description

You are given:

1. A set of nn items.

2. Each item has:

o Value (viv_i): Profit from including the item.

o Weight (wiw_i): How much the item weighs.

3. The knapsack has a maximum weight capacity (WW).

The goal is to find the subset of items that maximizes the total value while keeping the total weight
within WW.

Genetic Algorithm for the Knapsack Problem

The Genetic Algorithm (GA) can solve this problem by evolving a population of possible solutions over
generations. Below are the steps:
Steps of GA for the Knapsack Problem

1. Representation (Chromosome Encoding)

• Each chromosome represents a potential solution.

• The chromosome is a binary string of length nn, where each gene corresponds to an item:

o 11: The item is included in the knapsack.

o 00: The item is not included.

• Example: For 4 items, a chromosome [1,0,1,0][1, 0, 1, 0] means:

o Include items 1 and 3 in the knapsack.

2. Initial Population

• Randomly generate a population of chromosomes.

• Example:

o Chromosome 1: [1,0,1,1][1, 0, 1, 1]

o Chromosome 2: [0,1,0,1][0, 1, 0, 1]

3. Fitness Function

• The fitness of a chromosome is calculated as:

Fitness=Total Value of Selected Items (if total weight ≤W).\text{Fitness} = \text{Total Value of Selected
Items (if total weight \( \leq W\))}.

• If the total weight exceeds WW, penalize the chromosome by assigning a low fitness value.

• Example:

o Items:

▪ v=[10,20,30,40]v = [10, 20, 30, 40]

▪ w=[2,3,4,5]w = [2, 3, 4, 5]

o Knapsack Capacity: W=7W = 7

o Chromosome: [1,0,1,1][1, 0, 1, 1]

▪ Selected Items: 1, 3, 4

▪ Total Weight: 2+4+5=112 + 4 + 5 = 11 (Exceeds WW)


▪ Fitness: Penalized to a low value.

4. Selection

• Select chromosomes (solutions) for reproduction based on their fitness.

• Common methods:

o Roulette Wheel Selection: Probability of selection proportional to fitness.

o Tournament Selection: Choose the best from a random subset of chromosomes.

5. Crossover

• Combine two parent chromosomes to produce offspring.

• Example:

o Parent 1: [1,0,1,0][1, 0, 1, 0]

o Parent 2: [0,1,0,1][0, 1, 0, 1]

o Crossover Point: 2

o Offspring:

▪ Child 1: [1,0,0,1][1, 0, 0, 1]

▪ Child 2: [0,1,1,0][0, 1, 1, 0]

6. Mutation

• Randomly flip a gene in a chromosome to introduce diversity.

• Example:

o Original: [1,0,1,0][1, 0, 1, 0]

o Mutated: [1,1,1,0][1, 1, 1, 0]

7. Termination

• The algorithm stops when:

o A maximum number of generations is reached.

o No improvement in fitness is observed for several generations.

o A solution with the maximum possible value is found.


Example

Problem:

• Items:

o Values (vv): [10, 20, 30, 40]

o Weights (ww): [2, 3, 4, 5]

• Knapsack Capacity: W=7W = 7

Step 1: Initial Population

• Population:

o Chromosome 1: [1,0,1,0][1, 0, 1, 0]

o Chromosome 2: [0,1,1,0][0, 1, 1, 0]

Step 2: Fitness Evaluation

• Chromosome 1 ([1,0,1,0][1, 0, 1, 0]):

o Value: 10+30=4010 + 30 = 40

o Weight: 2+4=62 + 4 = 6 (Within WW).

o Fitness = 40.

• Chromosome 2 ([0,1,1,0][0, 1, 1, 0]):

o Value: 20+30=5020 + 30 = 50

o Weight: 3+4=73 + 4 = 7 (Exactly WW).

o Fitness = 50.

Step 3: Selection

• Chromosome 2 is selected as a parent due to higher fitness.

Step 4: Crossover

• Parent 1: [1,0,1,0][1, 0, 1, 0]

• Parent 2: [0,1,1,0][0, 1, 1, 0]

• Offspring:

o Child 1: [1,0,1,0][1, 0, 1, 0]

o Child 2: [0,1,1,0][0, 1, 1, 0]

Step 5: Mutation
• Mutate Child 1:

o Original: [1,0,1,0][1, 0, 1, 0]

o Mutated: [1,1,1,0][1, 1, 1, 0]

Step 6: Fitness Evaluation (Next Generation)

• Mutated Child 1 ([1,1,1,0][1, 1, 1, 0]):

o Value: 10+20+30=6010 + 20 + 30 = 60

o Weight: 2+3+4=92 + 3 + 4 = 9 (Exceeds WW).

o Fitness = Penalized.

• Child 2 ([0,1,1,0][0, 1, 1, 0]):

o Value: 20+30=5020 + 30 = 50

o Weight: 3+4=73 + 4 = 7 (Within WW).

o Fitness = 50.

Step 7: Repeat

• The process continues until an optimal solution is found.

Advantages of Using Genetic Algorithm for Knapsack Problem

1. Works well for large and complex problems.

2. Can handle constraints like weight capacity efficiently.

3. Finds approximate solutions quickly.

Limitations

1. May not always guarantee the optimal solution.

2. Requires careful tuning of parameters (mutation rate, population size).

3. Can be computationally expensive for very large datasets.

Real-World Applications

1. Resource Allocation: Allocating limited resources for maximum benefit.

2. Budget Optimization: Selecting projects or investments within a budget.

3. Logistics: Packing items for shipping or delivery.


4 Peaks Problem
4-Peaks Problem and Genetic Algorithm (GA)

The 4-Peaks Problem is an optimization problem often used to demonstrate how Genetic Algorithms
(GAs) can solve complex problems involving a balance between exploration (searching new areas) and
exploitation (refining known good solutions).

Problem Description

The 4-Peaks Problem is based on finding the optimal arrangement of binary strings that maximize a
specific fitness function. A binary string is considered "fit" if it has a certain structure of consecutive 1's
and 0's in either the first half or the second half of the string.

Key Parameters:

1. String Length (nn): The binary string has nn bits.

2. Threshold (TT): A predefined threshold value for the problem.

Fitness Function:

For a binary string xx, the fitness is calculated as:

f(x)={max⁡(num_leading_1’s,num_trailing_0’s)+R(x)if min⁡(num_leading_1’s,num_trailing_0’s)>T,0oth
erwise.f(x) = \begin{cases} \max(\text{num\_leading\_1's}, \text{num\_trailing\_0's}) + R(x) & \text{if }
\min(\text{num\_leading\_1's}, \text{num\_trailing\_0's}) > T, \\ 0 & \text{otherwise}. \end{cases}

Where:

• num_leading_1's: Number of consecutive 1's from the start of the string.

• num_trailing_0's: Number of consecutive 0's from the end of the string.

• R(x)R(x): A bonus reward if the condition


min⁡(num_leading_1’s,num_trailing_0’s)>T\min(\text{num\_leading\_1's},
\text{num\_trailing\_0's}) > T is satisfied.

Goal:

Maximize f(x)f(x).

Why Use Genetic Algorithms for 4-Peaks?

The problem is challenging because:

• It has a deceptive fitness landscape: high local optima may mislead traditional optimization
algorithms.

• It requires balancing exploration (diverse solutions) and exploitation (refining good solutions).
GAs are well-suited because they use:

1. Population-based search for diversity.

2. Crossover and mutation to explore new solutions.

Genetic Algorithm for 4-Peaks Problem

1. Chromosome Representation

• Each chromosome is a binary string of length nn (e.g., [1,1,0,0,1,0,0,0][1, 1, 0, 0, 1, 0, 0, 0]).

2. Initial Population

• Generate a population of random binary strings of length nn.

3. Fitness Function

• Compute the fitness of each string using the 4-Peaks formula:

o Count the number of leading 1's and trailing 0's.

o If both counts exceed the threshold TT, assign a fitness with a bonus reward (R(x)R(x)).

o If the condition is not met, assign a fitness of 0.

4. Selection

• Use techniques like:

o Tournament Selection: Select the fittest chromosomes from small random subsets.

o Roulette Wheel Selection: Probability of selection proportional to fitness.

5. Crossover

• Combine two parent strings to produce offspring.

• Example:

o Parent 1: [1,1,1,0,0,0,1,1][1, 1, 1, 0, 0, 0, 1, 1]

o Parent 2: [0,0,1,1,1,0,0,0][0, 0, 1, 1, 1, 0, 0, 0]

o Crossover Point: 4

o Child 1: [1,1,1,0,1,0,0,0][1, 1, 1, 0, 1, 0, 0, 0]

o Child 2: [0,0,1,1,0,0,1,1][0, 0, 1, 1, 0, 0, 1, 1]

6. Mutation

• Randomly flip bits in the offspring with a small probability.

• Example:
o Original: [1,1,1,0,0,0,1,1][1, 1, 1, 0, 0, 0, 1, 1]

o Mutated: [1,1,1,0,1,0,1,1][1, 1, 1, 0, 1, 0, 1, 1]

7. Termination

• The algorithm stops when:

o A maximum number of generations is reached.

o A string with the maximum possible fitness is found.

o No significant improvement in fitness over generations.

Example Walkthrough

Input:

• String Length (nn) = 10

• Threshold (TT) = 4

• Initial Population:

o Chromosome 1: [1,1,1,1,0,0,0,0,0,0][1, 1, 1, 1, 0, 0, 0, 0, 0, 0]

o Chromosome 2: [1,1,1,0,0,0,0,0,1,1][1, 1, 1, 0, 0, 0, 0, 0, 1, 1]

o Chromosome 3: [0,0,0,0,1,1,1,1,1,1][0, 0, 0, 0, 1, 1, 1, 1, 1, 1]

Fitness Evaluation:

• Chromosome 1: Leading 1's = 4, Trailing 0's = 6

o f(x)=4+10f(x) = 4 + 10 (bonus R(x)R(x)).

• Chromosome 2: Leading 1's = 3, Trailing 0's = 5

o f(x)=0f(x) = 0 (fails threshold condition).

• Chromosome 3: Leading 1's = 0, Trailing 0's = 6

o f(x)=0f(x) = 0 (fails threshold condition).

Crossover:

• Combine Chromosome 1 and Chromosome 3.

• Child: [1,1,1,1,1,1,1,1,0,0][1, 1, 1, 1, 1, 1, 1, 1, 0, 0]

Mutation:

• Mutate the child chromosome.

• Result: [1,1,1,1,1,1,0,1,0,0][1, 1, 1, 1, 1, 1, 0, 1, 0, 0]
Applications of 4-Peaks Problem

1. Benchmarking Genetic Algorithms: The 4-Peaks Problem is often used as a benchmark to


evaluate the performance of GA configurations.

2. Optimization Problems: The principles used to solve 4-Peaks can be applied to other challenging
optimization problems.

3. AI Research: It demonstrates the effectiveness of GAs in navigating complex search spaces.

By using GAs, the 4-Peaks Problem demonstrates how a combination of selection, crossover, and
mutation can navigate complex fitness landscapes efficiently.

MLP
• Previously, we chose the structure in a completely ad hoc way by trying out different structures
and choosing the one that worked best
• We can use a GA for this problem, although the crossover operator doesn’t make a great deal of
sense, so we just consider mutation
• However, we allow for four different types of mutation:
o delete a neuron
o delete a weight connection
o add a neuron
o add a connection.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy