Notes on "Genetic Algorithm Based on Java" (7/7): Personal Summary

Why Use Genetic Algorithms

Genetic algorithms are a subset of machine learning. In practice, genetic algorithms are often not the best algorithms to use to solve a single, specific problem. There is almost always a better, more targeted solution to any problem! So why bother?

Genetic Algorithms are an excellent multipurpose tool that can be applied to many different types of problems. This is the difference between a Swiss Army Knife and a proper screwdriver. If the task was to tighten 300 screws, you would jump up and find a screwdriver. But if the task is to screw a few screws, cut some cloth, punch a hole in the leather, and then open a bottle of ice soda to reward yourself for your hard work, the Swiss Army Knife is the better choice.

Also, Genetic Algorithms are a good primer for studying machine learning as a whole. If machine learning is an iceberg, genetic algorithms are part of the cutting edge. Genetic Algorithms are fun, exciting and innovative. The genetic algorithm's model is based on natural biological processes and establishes a connection between the computational world and the natural world. Write the first genetic algorithm and watch the amazing results emerge from chaos and randomness.

Other areas of research at the top of the machine learning iceberg are equally exciting, but they tend to focus on narrower and harder-to-understand problems. Not so with Genetic Algorithms, which are easy to understand, interesting implementations, and introduce many concepts that all machine learning techniques use.

Which problems are suitable for solving by genetic algorithm

Below is a list of problem characteristics that are good candidates for genetic algorithms:

  • If the problem is hard enough to write code to solve;
  • If one does not know how to solve this problem;
  • if the problem is constantly changing;
  • if it is not feasible to search for every possible solution;
  • If a "good enough" solution is acceptable.

Genetic Algorithm Basic Terms

Genetic algorithms are based on the concept of biological evolution.

  • Population: This is a collection of candidate solutions (individuals) to which genetic operations such as mutation and crossover can be applied.
  • Candidate solution (individual): A possible solution to a given problem.
  • Genes: The indivisible building blocks that make up chromosomes. Classical genes contain either 0 or 1.
  • Chromosome: A chromosome is a string of genes. Chromosomes define a specific candidate solution (individual). A typical chromosome might contain something like "01101011" in binary encoding.
  • Mutation: A process in which genes in candidate solutions are randomly altered to create new traits.
  • Crossover: A method in which chromosomes are combined to create a new candidate solution. This is sometimes called reorganization.
  • Selection: This is the candidate solution for the selection, the technique for breeding the next generation of solutions.
  • Fitness: A score that measures how well a candidate solution is suitable for a given problem.

General Genetic Algorithm Process

insert image description here

  1. The genetic algorithm starts, initializing the population of candidate solutions (individuals). This is usually random to provide uniform coverage of the entire search space. The parameters involved are population size.
  2. Next, the population is evaluated by assigning a fitness value to each individual in the population. At this stage, it is often necessary to pay attention to the current optimal solution and the average fitness of the population.
  3. After evaluation, based on the set of termination conditions, the algorithm decides whether it should terminate the search. Usually this is because the algorithm has reached the specified number of generations, or has found a suitable solution.
    1. If the termination condition is finally met, the algorithm breaks out of the loop, usually returning the last search result to the user.
    2. Some typical termination conditions are:
      • reach the maximum number of generations;
      • exceeds the time allotted to it;
      • find a solution that satisfies the required conditions;
      • The algorithm has reached a stable stage.
  4. If the termination condition is not met, the population goes through a selection phase where individuals are selected from the population based on fitness scores. The higher the fitness, the more chance an individual has to be selected. Select the purpose to prepare for the next step "Crossover and Mutation". The selection methods are:
    • Roulette selection (also known as fitness proportional selection). The higher the fitness of an individual, the more space it occupies on the roulette wheel, that is, the greater the probability of being selected. (Refer to Chapter 2)
    • Tournament selection. Randomly select some individuals from the population to enter the tournament. To compete by comparing the fitness values ​​of these individuals, and then select the individual with the highest fitness as the parent. (Refer to Chapter 3)
  5. The next stage applies crossover and mutation to selected individuals. This phase creates new individuals for the next generation. If it is the elite in the population (a small number of individuals with the highest fitness in the population), skip directly to the next generation. The parameters involved are crossover rate and mutation rate. After crossover and mutation, make sure you still get a valid solution (qualified individuals).
    1. Crossover methods are:
      • Uniform crossover. Each gene in the offspring has a 50% chance of coming from either the first parent or its second parent. (Refer to Chapter 2)
      • Single point cross. A position in the genome is randomly chosen to determine which genes come from which parent. The genetic information before the crossover position comes from parent 1, and the genetic information after that comes from parent 2. (Refer to Chapter 3)
      • Sort cross. In this crossover method, a subset of the chromosomes of the first parent is selected. This subset is then added to the same location on the offspring chromosomes. The next step is to add the genetic information of the second parent to the offspring's chromosomes. Usually start at the end of the selected subset and then include each gene of parent 2, as long as the gene is not already present on the offspring chromosome. (Refer to Chapter 4)
  6. At this point the new population returns to the evaluation step (step 2) and the process starts over. We call each turn of this cycle a generation.

Pseudocode for Basic Genetic Algorithm

generation = 0;
population[generation] = initializePopulation(populationSize);
evaluatePopulation(population[generation]);
while isTerminationConditionMet() == false do
    parents = selectParents(population[generation]);
    population[generation+1] = crossover(parents);
    population[generation+1] = mutate(population[generation+1]);
    evaluatePopulation(population[generation]);
    generation++;
End loop;

Guess you like

Origin blog.csdn.net/u011863024/article/details/120781958