- What are we doing?
- What we want to see
- We need a population
- Survival of the fittest
- A little class for saving the state of the evolution
If you want to interact with the final result first, you can play with it on to PyViz examples here: https://genetic-algorithm.pyviz.demo.anaconda.com/GA
How can you maximise the number of components in a laptop, while having size, weight and price constraints? For questions like these, we often want to reach for optimisation algorithms, and one particularly fun one is Genetic Algorithm.
Genetic Algorithm is cool so I created an interactive Genetic Algorithm dashboard with @HoloViews and @Panel_org.— Scott Condron (@_ScottCondron) July 18, 2020
Click to set a target and see the little critters evolve to be closest to it. Each time there is a generational update, the plot changes to show their positions. pic.twitter.com/5K9Ehp7wlo
For the sake of a fun visualisation, let's say the optimisation is "Wherever I click on the plot is the optimimum spot to find". We're going to use a population-based approach, Genetic Algorithm, in which there is a population of individuals (each individual representing a possible solution) which evolve across generations. Each solution is just the individual's x and y coordinates.
We want to see a kind of "evolution simulator" in which we click a spot on the plot and when we begin evolving, each generation moves closer to the place we clicked.
"And God said, Let us make man in our image". First, let's create a population.
#collapse-hide import math import numpy as np import pandas as pd import random from holoviews import opts from matplotlib import pyplot as plt import holoviews as hv import panel as pn from holoviews.streams import Stream hv.extension('matplotlib', logo=False)