Internet

The Double Hermeneutic of Boxcar2D

31 October 2017

If I asked you to design a 2D car to drive along an undulating track in a computer game, I would expect something simple: two big wheels with a body between, perhaps. Three wheels in a triangle that could flip and bounce. A computer would do it a bit differently.

I discovered BoxCar 2D in high school. It was shown as a demonstration of natural selection. When I returned to it this month, however, I was transfixed. It’s a relatively simple Flash application that tasks your computer with generating a car, within set limits, that can navigate the farthest along a bumpy track. You can find it here.

It begins completely randomly. Cars appear with eight wheels all over the body, cars that don’t make it past the first bump, cars with no wheels at all. Over its ‘generations’, it improves on each of them, always taking hints from its best car yet. The program creates, from purely random data, an attempt at the perfect car for a given track; what it produces often resonates with an alien beauty.

I spent two days just watching them move and grow, vaguely interested at first, and then fascinated. Before long, I was running it in four Chrome windows. I tasked my desktop with running the simulation 24/7 while I was working on my laptop, sleeping, going to class. Watching these organisms patiently develop from inanimate to proficient was hypnotic.

To navigate over variated hills, they developed a balanced isosceles structure. To crawl over slot gaps, they slowly began to resemble tank treads. For a sinusoidal hill-scape, they gradually simplified until they were nothing but two wheels connected by a light, narrow shaft.

You will likely be somewhat familiar with the default genetic algorithm. From a random population, it tests each, and ‘breeds’ the fittest together, randomly mutating to explore new avenues of speed or adaptability. But the one I find the most majestic is the particle swarm optimiser (PSO) which was originally developed to model the social behaviour of ants.

Imagine a graph girt by two axes, drawn on a squared notebook page – wheel-size on the X, and distance reached on the Y, for example. In this case, distance is what we want, so we call it ‘fitness’. As wheel-size (X) increases, let’s say this fitness (Y) increases as well, so that the graph ends up looking like a straight line. This is a straightforward correlation, representing a relationship between the two values. If we want the fitness to be maximised – as does the algorithm, as much as abstracted mathematical functions can ‘want’ anything – we would prefer the maximum wheel size.

Now imagine that the X-axis represents wheel size, but the Y-axis represents the distance between the two wheels, and there is a new Z-axis. The Z-axis represents fitness in three-dimensional space. The deeper the Z-value sinks into the page, the fitter the vehicle. Together, our three axes trace a 3D shape, which is called the ‘problem space’. We intend to find the optimum, what is called the global minimum: the lowest point in that shape.

The trouble is that initially, you have no idea what Z looks like, or where its minimum is. To ‘feel it out’ and find the minimum, you need some way of measuring it against the other values.

Imagine you drop 20 small ants, arranged into an even grid, on top of that shape. In the lowest point is an aromatic biscuit crumb, placed by a benevolent ant-deity. For simple problem spaces with a single minimum, at least one ant will always eventually find the crumb, and other ants follow the leader by its metaphorical pheromones. Your ants have ‘found’ the location of the optimum.

If it doesn’t hurt your brain too much, imagine that there is yet another axis to this shape. This axis exists in a fourth dimension – which makes the 3D ant metaphor a simplification – but don’t relax just yet, because the BoxCar2D algorithm uses 40: the sizes and angles of eight discrete vectors, and the size, angle, and position of eight discrete wheels. From the initial random assignment – our 40 dimensional ant drop – it computes a competent solution out of only random numbers. Isn’t that mind-bendingly beautiful?

But in such a complex problem-space as our boxcar’s, it is rare that the ‘true’ solution will be found naturally. Our ants sink into false crevices, never quite finding the opening of the true optimum’s narrow valley, and it is exceedingly difficult for them to climb out. They smell their crumb through the surface of the problem space, and are unable to crawl further away from it, convinced there is a way through.

Our boxcars do the best they can with what they are given – they are always blindly groping for the next-best solution. It’s how every living thing on Earth, including us, evolved – built from, in the words of my Year 12 biology teacher, “Duct tape and scissors”.

Like we humans, the boxcars never get a chance to rebuild from scratch. They are inefficient, like our vital biochemical processes; their traits are selfish, as Dawkins argued of our genes; they are imperfect.
But unlike us, they do not ever resign themselves. They may be mere mathematical machines, but written into the core of their algorithm is constant, unending struggle. They are always trying new things, yearning, striving to do better with the cow tools they have been given (from Larson’s The Prehistory of The Far Side) even when it certainly seems in vain.

If this perhaps sounds like objectivism, you would be wrong. The driving engine of optimisation is difference, multiplicity and diversity. Our ants, like our boxcars, would take eons to find anything close to the optimum in a complex environment without learning from each other. Diversity lends them more than just peaceful coexistence – it is essential for all of their betterment.

A homogenous population of cars, evolved purely for flat speed, would fail pretty much immediately when imposed with a bumpy track. Ants scatter when you remove their aromatic biscuit crumbs.
In a society which places so much emphasis on wealth and class, it is not surprising when those unprivileged or differently talented are insulted. But I wonder, who will instead thrive when our material conditions – our racetrack, our biscuit crumb – are inevitably changed?


Leave a Reply

Your email address will not be published. Required fields are marked *