MHALDER

Evolution and Genetic Algorithm

সমস্যা: কৃত্রিম বুদ্ধিমত্তায় (AI) Evolution এবং Genetic Algorithm


সমাধান:

1. মূল ধারণা: AI-তে Evolution


2. Genetic Algorithm (GA) কী?


3. গুরুত্বপূর্ণ পরিভাষা (Key Terms)


4. Standard GA-এর কাজের ধারা (Workflow)

  1. সমাধানগুলোকে Chromosome আকারে উপস্থাপন করো এবং Fitness Function নির্ধারণ করো।
  2. একটি random প্রাথমিক Population তৈরি করো।
  3. প্রতিটি Chromosome-এর Fitness নির্ণয় করো।
  4. নিম্নলিখিত ধাপগুলো পুনরাবৃত্তি করো যতক্ষণ না Stop Condition পূর্ণ হয় (যেমন সর্বাধিক প্রজন্ম বা লক্ষ্য Fitness):
    • Selection: ভালো Fitness-যুক্ত Parent বাছাই করো।
    • Crossover: Parent-দের মিশিয়ে সন্তান তৈরি করো।
    • Mutation: কিছু Gene এলোমেলোভাবে পরিবর্তন করো।
    • Elitism: সেরা Chromosome রেখে নতুন Population তৈরি করো।
  5. সর্বশেষে, সেরা Chromosome রিপোর্ট করো।

5. ধাপে ধাপে উদাহরণ : একটি শব্দ “Evolve” করা

লক্ষ্য: Genetic Algorithm ব্যবহার করে “CAT” শব্দটি evolve করা।
উপস্থাপন (Representation): প্রতিটি Chromosome একটি ৩-অক্ষরের string (প্রতিটি অক্ষর একটি gene)।
Alphabet: বড় হাতের A–Z।
Fitness: যত বেশি অক্ষর লক্ষ্য শব্দের (CAT) সঙ্গে মিলবে, Fitness তত বেশি।


(1) Setup


(2) Generation 0: Random Population (উদাহরণস্বরূপ)

IndividualChromosomeTarget মিল (CAT অনুযায়ী)Fitness
1Q Z P_ _ _0
2C Q RC _ _1
3B A T_ A T2
4D A X_ A _1
5C A PC A _2
6W T T_ _ T1

➡️ সেরা উদাহরণ: “C A P”“B A T” (Fitness = 2)


(3) Selection:
Tournament পদ্ধতিতে ভালো Fitness-যুক্ত Chromosome-এর নির্বাচনের সম্ভাবনা বেশি।
Parent হিসেবে সাধারণত সেরা কয়েকটি (যেমন “C A P” ও “B A T”) বেছে নেওয়া হয়।


(4) Crossover (One-point):
Crossover Point → Position 2 এবং 3-এর মাঝে

Parent 1: C A | P
Parent 2: B A | T

ফলাফল:


(5) Mutation:
অল্প সম্ভাবনায় (প্রতি gene-এ) Mutation ঘটতে পারে।
যদি “B A P”-এ Mutation ঘটে, কোনো একটি অক্ষর এলোমেলোভাবে বদলাতে পারে;
না ঘটলে সেটি অপরিবর্তিত থাকবে।


(6) পরবর্তী প্রজন্ম:

ধীরে ধীরে Selection ও Crossover-এর মাধ্যমে সঠিক অক্ষরগুলো একত্রিত হয়ে “C A T” দ্রুত তৈরি হয়।


(7) থামার শর্ত(Stop Criteria):


যখন লক্ষ্য শব্দ “CAT” তৈরি হয় বা সর্বাধিক প্রজন্ম পূর্ণ হয়, তখন থামো।
শেষে সেরা Chromosome (এখানে “CAT”) রিপোর্ট করো।


6. কেন এটি কাজ করে (Why this works)

এই তিনটি মিলে একটি guided random search তৈরি করে, যা নির্দিষ্ট নিয়ম জানা না থাকলেও ভালো সমাধান খুঁজে পায়।


7. ব্যবহারিক পরামর্শ (Practical Tips)


Example : Travelling Salesman Problem

Here’s the full transcribed text from the image titled “GA Approach”, which outlines the steps for applying a Genetic Algorithm (GA) to solve the Traveling Salesman Problem (TSP):


🧬 GA Approach:

  1. Chromosome Representation:
    A permutation of city indices.
    • Example: For 5 cities, a chromosome could be [1, 3, 5, 2, 4].
  2. Fitness Function:
    The total distance of the route represented by the chromosome.
    • Calculate the distance for each route permutation and use the inverse of this distance as the fitness value (shorter distances have higher fitness).
  3. Selection:
    Roulette wheel selection or tournament selection to choose parent chromosomes based on fitness.
  4. Crossover:
    Order crossover (OX) where segments of parents are exchanged while maintaining city sequence.
    • Example:
      • Parent1 = [1, 3, 5, 2, 4]
      • Parent2 = [2, 4, 3, 1, 5]
      • Offspring could be: [1, 3, 5, 4, 2]
  5. Mutation:
    Swap mutation where two cities in the chromosome are swapped to introduce variation.
    • Example: Mutate [1, 3, 5, 2, 4][1, 3, 2, 5, 4]
  6. Replacement:
    Replace the least fit chromosomes in the population with the new offspring.
  7. Termination:
    Continue for a set number of generations or until a satisfactory solution is found.

“Step 1: Initialization”, which sets up the Genetic Algorithm (GA) for solving the Traveling Salesman Problem (TSP):


🚀 Step 1: Initialization

Cities: Assume 5 cities with the following distances between them:

12345
1021045
220673
3106064
447606
553460

Initial Population: Let’s assume an initial population of 4 chromosomes:


“Step 2: Calculate Fitness”, which includes detailed distance and fitness calculations for four chromosomes in the Genetic Algorithm approach to solving the Traveling Salesman Problem (TSP):


🧮 Step 2: Calculate Fitness

Chromosome 1: [1, 3, 5, 2, 4]

Chromosome 2: [2, 5, 1, 4, 3]

Chromosome 3: [3, 4, 2, 1, 5]

Chromosome 4: [5, 2, 4, 3, 1]


Here’s the full transcribed content from the fifth image titled “Step 3: Selection, Step 4: Crossover, Step 5: Mutation”, which outlines the next stages in the Genetic Algorithm process for solving the Traveling Salesman Problem (TSP):


🎯 Step 3: Selection

Using roulette wheel selection, we select parents based on their fitness.


🔗 Step 4: Crossover

Parents: Let’s select Chromosome 1 and Chromosome 2 for crossover.

Order Crossover (OX):


🔄 Step 5: Mutation

Offspring 1 before mutation: [1, 3, 5, 4, 2]

Offspring 2 before mutation: [2, 5, 1, 3, 4]


Here’s the full transcribed content from the sixth image titled “Step 6: Replacement & Step 7: Termination”, which concludes the Genetic Algorithm cycle for solving the Traveling Salesman Problem (TSP):


🔁 Step 6: Replacement

New Population:


🛑 Step 7: Termination


Exit mobile version