# Drawing with genetic algorithms

# Live demo

Try out the demo on my personal blog.

# Explanation

I recently started researching Neuroevolution in the context of generating/optimizing neural networks. As a refresher exercise on the basics of genetic algorithms, I decided to code up a slightly contrived, yet not incredibly trivial application of genetic algorithms.

My formulation here was simple: given some continuous line, use genetic algorithm to find a vector representation of that same line.

The representation I went with for that line is a sequence of **<x, y>** coordinates. The “chromosomes” are modeled as a sequence of **<angle, distance>** pairs, such that after drawing the first point, subsequent points can be derived by computing the next point given the angle and length of the line relative to the current point:

Not the most industry disrupting concept, but fun enough to code up over a weekend.

The way the demo renders each generation of the algorithm is by drawing 10 or so of the lines with the worst fitness values in thick, faint, dark red. Another 10 or so low-ranking instances of the current generation in slightly darker color, and the top 10 or so instances of the current generation in thin, dark red. The target line is rendered in that lively, all natural green.

**Next Steps**

My next personal goal is to apply genetic algorithms to finding high performing neural nets, as demonstrated in the literature. I realize there is often no real benefit in doing it this way vs using back propagation with grid search or some other hyper parameter optimization strategy, but to follow the advice of wise people, “*a paper a week keeps the doctor away”*.