- We'll start by loading the necessary libraries for the script:
import os import numpy as np import matplotlib.pyplot as plt import tensorflow as tf
- Next, we'll set the parameters of the genetic algorithm. Here, we will have 100 individuals, each with a length of 50. The selection percentage will be 20% (keeping the top 20 individuals). The mutation will be set to be the inverse of the number of features, a common place to start for the mutation. This means that we expect one feature per child solution to change. We will run the genetic algorithm for 200 generations:
pop_size = 100 features = 50 selection = 0.2 mutation = 1./ features generations = 200 num_parents = int(pop_size*selection) num_children = pop_size - num_parents ...