← Back
others /

I wired a fruit fly connectome to osu! and it full combos

I took the full wiring diagram of a male fruit fly's nervous system, 165,122 neurons and 25 million connections, fed it the beatmap and trained a small readout on its motor neurons. Here's what that does and doesn't mean.

On a dark background, thousands of small colored dots and thin fibers form a fruit fly's nervous system lying on its side, a two-lobed brain joined by a narrow neck to a long nerve cord. A few glowing lime fibers leave the nerve cord and run into an osu! hit circle numbered 1, ringed by a lime approach circle.

This one started as a joke. Scientists have mapped every neuron in a fruit fly’s nervous system and every connection between them. osu! is a rhythm game where you click circles to the beat. What happens if you put the two together?

So I did. The fly’s real wiring diagram runs as a simulated network, the beatmap goes in through its sensory neurons, and a small trained readout turns its motor neurons into a cursor position and two keys. On all six difficulties of the map I used, the replays hit the official maximum score with 100% accuracy and a full combo.

A cartoon fly acting out the network's output. Its left legs tap Z and X, its right foreleg moves the pen, and the monitor shows the map it's playing.

That sounds a lot more impressive than it is, and most of this post is about why. The short version is that the fly doesn’t see the screen, the network itself never learns anything, and each difficulty has its own trained readout. The wiring is real though, and it does do real work. Cut the connections and the score drops to zero.

The wiring

The data is MaleCNS v1.0, the first finished connectome of the whole central nervous system of a male Drosophila. It was mapped by the FlyEM team at HHMI Janelia with the Cambridge connectomics group and Google. It covers the brain, the optic lobes and the ventral nerve cord, which is roughly the fly’s version of a spinal cord.

A 3D render of a fruit fly's central nervous system made of thousands of neurons in blue, pink, orange and yellow. A large round brain with an optic lobe on each side connects through a narrow bundle of fibers, the neck, to the elongated ventral nerve cord at the lower left.
The male fruit fly's central nervous system in the MaleCNS connectome. Image by the FlyEM Project Team, HHMI Janelia. More on the dataset at the Janelia MaleCNS page.

I kept every neuron marked as fully traced and every connection between them, with no weight cutoff.

What I kept Count
Traced neurons 165,122
Directed connections 25,563,197
Synapses 124,025,046
Motor and descending neurons used for output 2,129

The connectome tells you who connects to whom and through how many synapses. It doesn’t tell you how strong each synapse is in a living fly, or whether it excites or inhibits. So I had to make some calls. Each neuron’s main neurotransmitter is in the dataset, and I treated GABA and glutamate as inhibitory and everything else as excitatory. Glutamate is often inhibitory in flies but not always, so that’s a guess. Then I scaled each neuron’s inputs by its total incoming synapse count, so a neuron with ten thousand inputs doesn’t explode.

Making it run

Every 10 ms, every neuron updates with a simple rate equation.

s←s+λ(tanh⁡(gWs+b+u)−s)s \leftarrow s + \lambda \left( \tanh(g W s + b + u) - s \right)

Here ss is the activity of all 165,122 neurons, WW is the signed, normalized wiring, g=0.9g = 0.9 is a gain that keeps the network from blowing up, λ=0.65\lambda = 0.65 is how fast each neuron moves toward its new value, bb is a small random bias and uu is the sensory input. Real neurons spike and have all kinds of channels and delays. This has none of that. It’s the simplest model that lets activity flow through the real wiring.

It runs slower than real time, so the network plays ahead of time and its output becomes a replay file.

What the fly sees

Not the screen. Turning pixels into something a fly brain could use would be a whole other project. Instead the network gets the beatmap itself. For right now, 40 ms ahead and 80 ms ahead, it’s told where the current object is, whether it’s a circle, slider or spinner, how far it is from its start and end time, and a few timing signals that bump up right around each hit. That’s 46 numbers.

Those numbers go into the neurons the dataset labels as sensory or visual projection neurons. Each one gets a random mix of four of the inputs. This adapter is random and fixed, and it’s not anatomy. Real flies have no neuron for “slider ends in 30 ms”.

This is the biggest caveat in the whole project. The network is handed exactly where to aim and exactly when to press. Its job is to carry that through 165,122 neurons and out the other side in a form a readout can use.

The only part that learns

The wiring never changes. The one thing that’s trained is a linear readout from the 2,129 motor and descending neurons to four outputs, cursor x, cursor y, key Z and key X. This setup has a name, reservoir computing. You use a fixed recurrent network as a big pool of signals and only train the last layer.

To train it I wrote a scripted player that knows the map. It glides between objects, follows sliders, spins spinners and alternates keys so it can hit a new circle while still holding a slider. I ran the network over the whole map, recorded the motor neurons, and fit the readout to copy the scripted player with ridge regression. Frames within 40 ms of a hit count five times as much, since that’s where a miss breaks the combo. Then I tried six regularization strengths and five press thresholds and kept whichever combination scored best in the real game.

Results

Each replay was exported as an .osr file, loaded back and scored by the official osu!lazer code with default rules and no mods. The map is the Battle Sirens mapset.

Difficulty Score Accuracy Combo Wiring cut
waji’s Easy 1,002,380 100% 227 / 227 0
Normal 1,002,600 100% 296 / 296 2
Hard 1,002,110 100% 686 / 686 0
Insane 1,002,090 100% 696 / 696 0
Djulus’ Hyper 1,001,640 100% 652 / 652 0
Extra 1,001,680 100% 780 / 780 0

Every score is the maximum possible for that difficulty. The last column matters most. It’s the same trained readout with the connections between neurons switched off, so the sensory input never reaches the motor neurons. It scores 0 to 2 points. An untrained readout scores 0 everywhere. So the score isn’t coming from the readout alone. The signal has to travel through the fly’s wiring to reach the motor neurons in a usable form.

That doesn’t mean the fly’s wiring is special, though. I never tried a random graph of the same size, and a random reservoir might do just as well.

It doesn’t generalize

Each difficulty has its own readout. I took the one fitted to Normal and ran it on the other five difficulties of the same song.

Normal readout on Score Accuracy
waji’s Easy 155,546 70.92%
Hard 21,452 44.39%
Djulus’ Hyper 17,393 42.61%
Insane 6,678 29.66%
Extra 2,837 17.84%

Same song, same rhythm, and it falls apart as soon as the objects move. It memorized one map. A fly that could actually play osu! would need training across many maps and probably a very different input than a list of object positions.

Two big numbers that cancel out

The part I find most interesting has nothing to do with osu!. The readout is linear, so for any moment you can add up exactly how much each motor neuron pushes each output, and split that into positive and negative pushes.

The same moment as the replay above. Left, motor neurons at their real positions, colored by the output they drive. Right, the running drive for each output, with the inhibitory and excitatory sums under each trace.

For each output, the excitatory and inhibitory sums are each around 1,500 units, and they almost cancel. What’s left over is small, and that leftover is the entire motor command. A tap on Z is a slight tilt in a near-perfect tug of war. Real motor systems are often described the same way, with excitation and inhibition held in balance, but here it’s just as likely a side effect of fitting a linear readout to two thousand correlated signals. It’s still fun to watch.

The viewer

Most of the time on this project went into the viewer rather than the model. I wanted to see what the network was doing, not just a score. It records all 165,122 neuron states every 10 ms for every replay, and plays them back in sync with the game, the hit sounds and the cartoon fly.

Brain · every neuron's activity, placed where its cell body sits in the real fly.
Game · the cursor and key presses that come out the other end.

You can click a neuron and see its strongest outgoing connections, drawn along the real neuron skeletons through the real synapse locations from the dataset.

So, can a fly play osu!?

Not really. The wiring carried a signal it was handed, and a readout turned that into clicks. It was still fun to watch 165,122 neurons flicker along to a beatmap, and to see a fruit fly full combo Extra, even a pretend one.

Keep reading

All posts ↗
ESC
↑↓ navigate ↵ open