DEV Community

Cover image for The Real Fruit Fly Brain Told Me Where I Was Cheating
Constant Itis
Constant Itis

Posted on

The Real Fruit Fly Brain Told Me Where I Was Cheating

A neon sci-fi fruit fly with a glowing brain stands between “X Danger” and “X Safe,” representing inherited memory, reversal learning, and an alternate escape path in The Fly and the Graph: Arc II.

The first part of this series used a deliberately tiny fake brain.

A 64-neuron recurrent network.

That was useful because I could control every assumption, break things on purpose, and ask some weird questions about memory without pretending I had simulated biology.

Can memory survive when the brain that learned something is destroyed?

Can you move that memory into a fresh brain?

Can two identical brains become different individuals because they lived different histories?

Can you fabricate a memory instead of earning it through experience?

Can you merge two histories?

The toy gave me answers.

Interesting ones.

But eventually the obvious problem becomes impossible to ignore.

It is still a toy brain I made up.

So I finally replaced it with the real thing.

Well, part of the real thing.

I am now running the actual fruit fly memory circuit

The dataset is MaleCNS v1.0, the reconstructed nervous system of a male fruit fly.

Instead of loading the entire thing, I pulled out the mushroom body.

The mushroom body is heavily involved in associative learning and memory in flies.

This is where things like sensory cues, reward, punishment, and learned behavioral preference start becoming very relevant to the experiments I have already been doing.

The subgraph I pulled contains:

4,064 Kenyon cells
97 mushroom body output neurons
344 dopamine-related neurons

4,505 neurons total
roughly 998,000 directed synaptic connections
Enter fullscreen mode Exit fullscreen mode

This is no longer:

rng.standard_normal(...)
Enter fullscreen mode Exit fullscreen mode

pretending to be a brain.

These are the actual reconstructed connections between neurons in the published connectome.

That was the first moment where this project felt different.

The fly gets a vote now.

First question: does the thing even run?

Before attaching Mycelium, before teaching it anything, before doing any of the weird memory-transfer experiments again, I wanted to ask the most boring question possible:

If I push activity through the real mushroom body wiring, does it behave like a usable neural network or immediately turn into numerical garbage?

So I ran it.

Nothing exploded.

The neural states stayed finite and bounded.

Maximum activity was around 0.79.

Mean activity was around 0.09.

That sounds boring.

It is boring.

That is good.

The first thing you want from a neural simulation is for it to not spontaneously become infinity.

Then I gave it three different sensory inputs.

Again, these were not biologically correct sensory inputs yet. More on that shortly.

I just needed to know whether different inputs could produce meaningfully different internal states.

They did.

The resulting activity patterns had cosine similarity around 0.30.

In normal English:

the real mushroom body wiring can tell different inputs apart.

If every cue produced basically the same brain state, this project would stop right here.

There would be nothing useful for memory to associate with anything.

But different inputs produced different internal representations.

Cool.

Then the real brain immediately showed me where I was cheating.

Problem number one: my fruit fly brain would not shut up

About 80 percent of the Kenyon cells were active.

That is wildly wrong.

Kenyon cells are supposed to produce sparse representations.

A real fly does not respond to an odor by lighting up almost every neuron in the mushroom body like a Christmas tree.

Only a relatively small subset should strongly respond to a particular cue.

My simulation had basically done this:

INPUT

EVERYBODY FUCKING GO
Enter fullscreen mode Exit fullscreen mode

Why?

Because in the first pass I treated every connection as excitatory.

Every synapse effectively said:

make the next neuron more active

That is obviously not how nervous systems work.

Brains also contain inhibitory signaling.

Some neurons are there specifically to suppress activity, regulate gain, sharpen representations, and stop the entire network from screaming at once.

And here is the fun part.

The thing I needed was already sitting in the connectome.

Meet APL, apparently

One of the strongest partners connected to the Kenyon cells was APL.

APL is a large inhibitory neuron associated with the mushroom body.

It uses GABA.

In extremely sophisticated neuroscientific terminology, its job is partly:

everybody calm the fuck down.

Which is exactly what my simulation was missing.

And the MaleCNS data already contains predicted neurotransmitter annotations.

So instead of every edge being:

+
Enter fullscreen mode Exit fullscreen mode

the next version can actually distinguish:

excitatory connection
inhibitory connection
Enter fullscreen mode Exit fullscreen mode

That means the fix is not:

adjust some random parameter until the graph looks biologically convincing

The fix is:

stop lying about what the neurons do.

Let inhibitory neurons inhibit.

Then see whether the sparse coding emerges from the real wiring.

That is a much better kind of bug.

Problem number two: I was teleporting smells into the brain

The second problem was even more obvious once I looked at it.

My "sensory inputs" were fake.

I was selecting Kenyon cells and injecting activity into them directly.

That was fine for the first spike.

I only wanted to know whether the mushroom body graph loaded, remained numerically stable, and generated different states for different inputs.

But a fruit fly does not smell something and have information magically appear inside its Kenyon cells.

There is actual circuitry upstream.

Very roughly:

odor
  ↓
olfactory receptors
  ↓
antennal lobe
  ↓
projection neurons
  ↓
Kenyon cells
  ↓
mushroom body output
Enter fullscreen mode Exit fullscreen mode

So if I want to say the next experiment uses real sensory input, I need to stop teleporting information into the memory circuit.

The next version needs the projection-neuron layer.

A cue should activate real upstream neurons.

Those neurons should feed the Kenyon cells through the actual reconstructed connections.

Then the mushroom body gets whatever representation the biology produces.

Not whatever representation I decided to hand it.

This is why I wanted to use the real connectome

This is already doing exactly what I hoped it would do.

The toy model made the ideas easy to test.

The real biology is now showing me which assumptions were bullshit.

The first version said:

sensory input enters here.

The real fly says:

no it fucking doesn't.

The first version said:

connections push activity forward.

The real fly says:

some of these connections exist specifically to suppress activity.

Good.

That is the point.

Every time the toy disagrees with the real fly, the fly wins.

What actually worked

So the first real-connectome milestone is mostly cleared.

The real mushroom body:

  • loaded successfully
  • contains the expected major learning populations
  • includes thousands of real Kenyon cells
  • includes mushroom body output neurons
  • includes hundreds of dopamine-related neurons
  • produces bounded neural activity
  • produces different neural states for different inputs

And the spike exposed two things that still need to be fixed before I call the sensory representation remotely honest:

1. use real neurotransmitter signs so inhibition actually inhibits

2. feed cues through the real projection-neuron sensory pathway
Enter fullscreen mode Exit fullscreen mode

That is the next experiment.

And then the fun part starts again

Once the mushroom body produces sparse, distinguishable states from real upstream sensory input, I can move to reward.

The current toy version of Flymem has a hand-coded reward signal.

Good thing happens:

+1
Enter fullscreen mode Exit fullscreen mode

Bad thing happens:

-1
Enter fullscreen mode Exit fullscreen mode

That is useful engineering.

It is not how a fly works.

The real mushroom body has dopaminergic neurons involved in reinforcement.

Those neurons are already in the graph I pulled.

So eventually the loop becomes something more like:

real sensory input
      ↓
projection neurons
      ↓
Kenyon cells
      ↓
mushroom body state
      ↓
action / outcome
      ↓
real dopaminergic populations
      ↓
learning
Enter fullscreen mode Exit fullscreen mode

Only after that works do I attach Mycelium again.

Then I rerun the experiments that started this whole mess:

learn something

reset the brain

restore the external memory

swap two histories

fabricate a history

merge two histories
Enter fullscreen mode Exit fullscreen mode

Except this time the substrate underneath them is not a random little matrix I invented.

It is the reconstructed wiring of the fruit fly's actual associative-learning circuit.

And the real fly has already started correcting my homework.

Good.

That is exactly what I wanted.

Next: why 80 percent of my fruit fly brain was firing, and whether one enormous inhibitory neuron can make everybody shut the hell up.


Clone it and break it.

The toy repo from Arc I is still here:

git clone https://github.com/constant-itis/flymem && cd flymem && python3 flymem.py
Enter fullscreen mode Exit fullscreen mode

The mushroom body I pulled is public too, so you can grab the exact same wiring and check whether I read it right:

pip install neuprint-python
# point a Client at server "neuprint.janelia.org", dataset "male-cns:v1.0"
# (free per-user token from the site), then fetch the KC / MBON / DAN populations
Enter fullscreen mode Exit fullscreen mode

🧪 What I actually ran

What I ran. A scoping spike, not the toy. It connects to neuPrint (neuprint.janelia.org, dataset male-cns:v1.0) with neuprint-python, fetches the mushroom body populations (Kenyon cells, mushroom body output neurons, dopaminergic neurons) and their reconstructed adjacencies, builds a directed weighted graph from those synapse counts, and pushes activity through it with a crude column-normalized tanh update. No learning, no memory attached yet. The numbers in this post are that run: 4,064 KC / 97 MBON / 344 DAN, 4,505 neurons, roughly 998,000 edges, max activity around 0.79, mean around 0.09, and cross-cue cosine similarity around 0.30. The real-fly adapter code stays private until it is proven, so this post ships the neuPrint pull as the reproducible part.

⚠️ Where I might be wrong

The honest caveat. This is first contact, and it cheats in two ways I already know about. Every edge was treated as excitatory, which is why 80 percent of the Kenyon cells fired instead of the biological handful, and the fix is to use the predicted neurotransmitter signs so APL and friends can actually inhibit. And the sensory input was teleported straight into Kenyon cells instead of arriving through the real projection-neuron pathway. The propagation rule is a hand-picked tanh, not fitted dynamics. A connectome is wiring, not learning rules, so a working substrate does not mean a working fly yet. Clone it, pull the same mushroom body, and tell me where I read the biology wrong.

Top comments (0)