Skip to content

KartikChugh/genetic-seeker

Repository files navigation

logo

Overview

Genetic Seeker is an evolutionary simulation in which agents compete to locate a moving target with no instruction other than genetic information. The application is built in Swing and serves as a pure Java re-implementation of the CodeBullet project done in Processing.

Genetic Algorithms

GAs are a machine learning approach that employ random search and natural selection to discover heuristic solutions to optimization problems, as opposed to gradient-guided techniques. They are rooted in the idea that machine learning models can "evolve" to become better over time, with some inspiration from biology. At the heart of the algorithm are genes, which shape the behavior of individuals and spread among the broader population.

Evolutionary Design

A brief summary of the genetic operators and design decisions in Seeker:

  • Fitness scores results and efficiency. The fitness function scores members first according to their distance from the target and second according to the steps they took to get there, to ensure convergence to a straight path.
  • Fitness-proportionate selection. FPS offers a balance between evolutionary pressure and genetic diversity by selecting population members with a chance proportional to their fitness (e.g. a fitness score of 6.0 provides twice the odds of survival over a score of 3.0).
  • Genetic representation. A members's genome consists of several hundred acceleration vectors, which are read sequentially to guide motion.
  • Visual phenotype. Members are colored differently based on their genetic codes. This tends to reveal clusters and highlights the growth and decline of sub-groups over time.
  • Cloning with mutation. Single-parent cloning is the simplest mechanism for genetic recombination, but suffices for this problem. Parents are culled from each generation and cloned until repopulation, passing down their genes with small chances of point mutation (randomized new genes).
  • Elitist selection. The fittest member of each generation is automatically survived to the next. Elitism prevents populations from wholly regressing by mutation.
  • Dynamic problem. The target moves to a new location periodically, putting selective pressure on the population to adapt.

Experimentation

You can run the latest version or tinker with the code to experiment with different settings. Note that you'll need Java 7 or up.

Instructions

These instructions are for working with the code.

  1. First, you'll need to clone this repo to your local machine, using git clone https://github.com/KartikChugh/genetic-seeker.git or downloading it as a zip.

  2. Open the project in the editor of your choice (IntelliJ recommended) and make tweaks as desired. Most hyperparameters have been factored out to SeekerPanel.java, while a few remain in Dot.java. Collectively, these include:

    • Mutation chance - a gene's odds of being randomized (default: 0.5%)
    • Population size - how many agents to spawn (1000)
    • Seed - seeds the random mutation/selection processes (-1 for random seed)
    • Genome length - number of instructions for an agent (scales to resolution height)
    • Max speed - terminal velocity for an agent (7.0)
    • Relocation interval - number of generations before the target moves (15)

Others are documented in the code.

Updates

Genetic Seeker will most likely be rewritten using the Visua framework. Stay tuned!