Curve Fitting using Genetic.js

From a plot of vertices, this genetic algorithm optimizes a continious function to best fit the data (aka least squared error). Genetic.js automatically runs the algorithm in the background with web workers so that the UI experience isn't compromised.


Given the population parameters below, the simulation will run and interpolate color, transparency, and line-thickness to show how solutions evolve over time. The best-fit solutions are narrow and red. The least fit are large, purple, and semi-transparent.

Error (Avg):
Error (Stdev):
VertError (Avg):
Solution: Press 'Compute' Button
Mutation with
Crossover with

How it Works

This genetic algorithm optimizes the the coefficients of a polynomial to fit a plot of data. Given a polynomial such as: ax4 + bx3 + cx2 + dx + e. The coefficients a, b, c, d, e are randomly seeded and then iteratively selected, mutated, and crossed over a number of generations.

A random stepping drift is applied to entities (represented as an array of coefficients) when selected for mutation. Crossover uses single point interpolation between two parents.

Crossover can be disabled by setting it to 0% (0.0 from the dropdown), which causes the simulation to run as an evolutionary algorithm.

Helpful Links