AI / Machine Learning
-
December 8, 2022

How Natural Selection is Present in Genetic Algorithms

Natural selection refers to the process through which a population of living individuals can adapt and change to the conditions of their environment. But, it may come as a surprise to know that natural selection is present in algorithms.

While individuals are not all the same, they have variations, and some might have traits better suited to the environment than others. The more adaptive individuals are more likely to survive and reproduce, i.e., those who can pass their skills or traits to the following generations.

Some algorithms, known as genetic algorithms, are inspired by this concept and follow the same logic in a simulated environment to find the most optimal solution given certain conditions.

In this article, we will look at the following:

  • What is a genetic algorithm?
  • Where are genetic algorithms applied?
  • What are the pros and cons of genetic algorithms?
  • How are genetic algorithms used in machine learning?

What is a Genetic Algorithm?

A genetic algorithm (GA) is a heuristic based on natural selection and genetics by simulating how species adapt to environmental changes to survive. The surviving individuals can reproduce and build the next generation.

Genetic algorithms

We have the following stages that take place in a genetic algorithm:

  1. Initial population: a set of individuals that compose the first generation.
  2. Selection: selecting the best individuals to create the next generation.
  3. Crossover: a crossover point is chosen randomly from within the genes.
  4. Mutation: some genes are subjected to mutation with a low random probability.

And there is also a fitness function that needs to be optimized. This function tests the solution and evaluates its performance, giving us a score representing that individual’s fitness level.

Genetic Algorithm Stages

As mentioned, specific steps are taken at each stage of a genetic algorithm. Let’s take a look at each in more detail.

Initial Population

An initial set of individuals make up the population. Each of them is a solution for the problem that you would like to solve. It comprises a group of variables (genes) joined in a string representing the solution (chromosome).

Selection

The best individuals pass their genes to the next generation during selection. Parents are selected for the next generation based on their fitness scores. A higher score means a higher probability of reproduction.

Crossover

This step plays a vital role in reproduction; a crossover point is selected randomly across genes, and the genetic information from parents is combined to create offspring.  

Graph showing genetic information from two parents and one offspring.
Crossover – image created by the author

Mutation

When a new offspring is created, some genes are mutated with a low random probability. This implies that some bits in the bit string can be flipped. In this image, we can see illustrated, the mutation of an offspring:

Graph showing genes created by mutation.
Genes Mutation – image created by the author

The mutation is performed to maintain diversity within the population and prevent the event called “premature convergence,” which happens when all individuals in a population-based algorithm are trapped in a local optimum.

Observation

The Fitness Function should be a precise, understandable, efficient, and quantitative measure, and the results should be intuitive.

Where can Genetic Algorithms be applied?

The most commonly used application is for optimization issues, particularly the famous “traveling salesman problem,” used to find the best route that reduces time and cost for traveling. But, genetic algorithms have other applications in different areas, such as economics, medicine, fashion, and more. Let’s take a look at these in detail.

Fashion

Fashion is changing over time and adapting to the environment, making genetic algorithms an excellent approach to bringing the fashion industry up to date. The following paper introduces a GAN (Generative Adversarial Network) used to generate new fashion styles. The genetic algorithms are introduced by performing an evolutionary search after developing the different styles.

Also, the fashion industry is very subjective, so that humans won’t be out of the equation. In the following paper, a new concept is introduced “Interactive Genetic Algorithm” (IGA) that can be used to get a human response as fitness value.  

Healthcare

We can also apply genetic algorithms to healthcare, where many optimization problems exist. Assigning patients to rooms, urgent care, waiting lines, resource optimization, and healthcare processes could all benefit from genetic algorithms. A recent study highlighted that GA had been used in image processing for radiology and detecting cancer.  

Genetic algorithms

Image processing

Image processing can take shape in many different ways. See how the following paper uses genetic algorithms for image matching.

Music Generation

Musicians can use technology to generate new pieces of music and find inspiration by creating synthesized sounds. Many research papers are focused on investigating the generation of music through genetic algorithms. You can see some research papers that utilize different fitness function approaches. Let’s take a look at a few.

The authors of a music recombination paper extracted musical features from two MIDI files and generated new music with a genetic algorithm. The fitness function considers features like time, velocity, and low and high notes, among other values.

A human-robot musical improvisation paper introduced an interactive musical system that uses genetic algorithms to create a collaboration between humans and a robotic instrument. The instrument is adjusted in real time according to a fitness function based on similarities between the two compositions.

Melody, harmony, and rhythm are different elements of music. In a generative genetic algorithm paper, a melody is generated by genetic algorithms. In this case, a Generative Genetic Algorithm (GGA) with a Long Short-Term Memory (LSTM) recurrent neural network is used as an objective function.

Artificial life

It is not hard to imagine that this algorithm is used to study animals’ behavior by simulating their reality with computer models. This field of research is called artificial life.  

Pros and Cons of Genetic Algorithms

The advantages and disadvantages associated with genetic algorithms are a discussion that is likely to grow as we become more familiar with them. Let’s take a look at what we know so far.

Genetic algorithm advantages:

  • Does not need a lot of data.
  • Good for parallel processing.
  • Good for optimization problems.
  • Adaptability – provides a solution to a problem that improves over time.

Genetic algorithm disadvantages:

  • Does not guarantee the quality of the final solution to a problem.
  • Genetic algorithms should not be used to resolve simple problems.
  • Computational challenges are present when repetitive calculations of the fitness function take place.
  • The fitness function is not trivial to define, and without proper implementation, the algorithm may converge to a solution that is not optimal.

Genetic Algorithms and Machine Learning

Genetic algorithms can be used in machine learning for function optimization. Another use of machine learning with these algorithms is to generate an optimal neural network architecture for a solution.

This is where the concept of neuroevolution comes in, which uses evolutionary algorithms to optimize neural networks.

This process enables relevant capabilities such as learning neural network-building activation functions, hyperparameters, and architectures. In neuroevolution, a population of solutions is maintained during the search, enabling parallelization.

The Takeaway

This article provided an in-depth overview of genetic algorithms and their use in different areas and industries. We also looked at the pros and cons of using these algorithms.

We may have only scratched the surface with genetic algorithms, and it will be fascinating to see how they evolve as technology continues to evolve.

What are your thoughts on genetic algorithms? Do you think its use in machine learning will evolve? Let us know in the comments section.