fly-api · plain-language explainer
How the Fly Learns
The demo's fly brain learns that one smell means a treat is coming. But the model is a wiring diagram — a map of a brain, not a brain. So what actually changes when it learns? A small set of connections gets weaker, by the rule real flies use. Five pictures tell the story; the numbered notes hold the detail.
On a phone, tap a note number to open it.
1 · The fly's memory organ
A smell wakes a few dozen of the five thousand memory cells — a
different few dozen for each smell.The memory cells are Kenyon cells (KCs). Each listens to a random handful of the 685 projection neurons leaving the antennal lobe and fires only when several agree; the two giant APL neurons feed inhibition back so only the best-matched cells win (sparse coding). In our runs each odor activates 1–4% of KCs, two odors' codes overlap by ~1% (Jaccard 0.01), and the same odor gives the same code every time (Jaccard 1.00).
Each memory cell connects to a few of about a hundred decision cells,
which vote approach or avoid; reward cells fire when something good
happens.Decision cells = mushroom-body output neurons (MBONs), 96 in 35 types. Reward cells = dopamine neurons: 307 PAM (reward) and 16 PPL1 (punishment). Counts come from the model's cell-type labels (experiments/learning/mb_subnet_ids.json).
Those memory-to-decision connections are the knobs. Reward cells are the
hand that turns them.
2 · How do we know this is where flies learn?
For most brains, including ours, nobody knows the mechanism of learning at this level. The fly's memory organ is the exception. Damage it and flies can't learn smells.Heisenberg 2003 reviews the classical mutant and lesion evidence. Aso et al. 2014a showed the anatomy reads as an architecture for learning: a sparse KC code feeding 15 compartments, each pairing specific dopamine neurons with specific MBONs. Flash the reward cells with light instead of giving sugar, and flies learn anyway.Claridge-Chang et al. 2009 ("Writing memories with light-addressable reinforcement circuitry"); Aso et al. 2014b mapped which dopamine neurons write reward vs. punishment. This optogenetic substitution is why our simulation can deliver reward directly at the dopamine neurons (§5). Record a memory-to-decision connection before and after training and it is weaker, not stronger.Hige et al. 2015, by patch-clamp: pairing an odor with dopamine-neuron activity depresses that odor's KC→MBON synapses in the matching compartment. And dopamine, released by the reward cells onto exactly those connections, is the trigger.Cohn, Morantte & Ruta 2015: dopamine release is compartmentalized and state-dependent. Handler et al. 2019: the sign and timing of the plasticity follow from two dopamine receptors with different kinetics. Modi, Shuai & Turner 2020 review the whole story; Bennett et al. 2021 is one of several computational models built on this rule.
3 · The map
In 2024 one team traced every neuron and connection in a fly brain from microscope images,FlyWire (Dorkenwald et al. 2024): 139,255 neurons and ~50M synapses from one adult female, community-proofread, with a synapse count for every connected pair. Schlegel et al. 2024 add a class and type for every neuron — that is how we know which cells are sensor, memory, decision, or reward cells; the groups in the diagrams are selected by those published labels, not by us. and another turned the map into a simulation: each neuron a simple fill-up-and-fire unit, each connection as strong as its synapse count.Shiu et al. 2024: leaky integrate-and-fire neurons with published constants we did not change — rest/reset −52 mV, threshold −45 mV, membrane time constant 20 ms, synaptic decay 5 ms, refractory 2.2 ms, delay 1.8 ms; each synapse contributes 0.275 mV, signed by the predicted neurotransmitter. The model reproduces known responses (sugar → proboscis extension) with no fitting. A map shows where the roads go, not how traffic reshapes them: it contains no learning rule. Any such rule is added by hand, so the honest question is whether it is the right rule in the right place.Also absent: receptor identities, neuromodulator release, gap junctions, short-term synaptic dynamics. For this demo we cut the map to the olfactory pathway plus mushroom body — 8,991 neurons, 792k synapses — which surfaced a finding: the published whole-brain model is bistable, and almost any central input tips it into a permanent ~8,400-neuron storm. Four structural edits (each biologically argued, none a parameter fit) remove it while leaving odor coding intact; listed in the appendix, audited in notes.md.
4 · The rule
The model's memory is a list of about 62,000 numbers — the strength of every memory-to-decision connection — and nothing else carries over from one moment to the next.62,261 KC→MBON connections (recomputed from the subnet's cell lists and the FlyWire connectivity table). Weights start at the connectome value; membrane voltages and synaptic conductances are reset between episodes, so this vector is the only persistent state.
That is the whole algorithm.Verbatim from learning_driver_mb.py:kc_active = KCs with ≥1 spike this episode
pam_hz = mean PAM DAN rate this episode
if us and pam_hz >= 1.0: # dopamine gate
hot = synapses whose presynaptic
KC is in kc_active
w[hot] *= (1 - eta) # eta = 0.5Dopamine-gated long-term depression at KC→MBON, once per episode. No objective, no gradient, no hidden state.
Its place, trigger, and direction are the fly's (§2). The fine print is ours:
one step at the end of each half-second instead of a gradual, timing-sensitive
change;Real plasticity is continuous and receptor-mediated, with sign and size depending on odor–dopamine timing at sub-second resolution (Handler 2019). Our "same episode = coincident" abstraction cannot reproduce forward-vs-backward pairing effects.
one reward signal for all decision cells instead of many;Biology: 15 compartments, each dopamine-neuron type writing to its own MBON zone, appetitive and aversive traces in parallel (Aso 2014, Cohn 2015). Model: one scalar gate (mean PAM rate ≥ 1 Hz) and one uniform η. Real dopamine neurons also make fast synapses; we zeroed those for stability, so dopamine acts only through the scripted rule.
and memories that never fade.Depression only, permanent: no recovery, extinction, or forgetting. The full biology-vs-model ledger is in the appendix.
5 · Teaching the fly
Pavlov's dog drooled at the bell; a fly walks toward a smell that came with sugar.The smell is the conditioned stimulus (CS), the sugar the unconditioned stimulus (US). The classic assay is Tully & Quinn 1985: train with odor A + sugar or shock and odor B alone, then let flies choose between A and B in a T-maze; the fraction choosing A is the memory score. B is the control — it experiences everything except the smell–reward coincidence. We present smell A with the reward cells switched on, five times, with smell B and no reward in between.CS: a disjoint set of six ORN receptor classes, count-balanced, driven at 500 Hz for 0.5 s. US: the 307 PAM dopamine neurons at 60 Hz. We inject the US at the dopamine neurons because the model's own sugar→PAM route is silent in this regime (measured: PAMs at 0 Hz under sugar drive) — a documented limitation with a real experimental precedent (§2, experiment 2). Afterwards the decision cells' response to A has dropped by about 99%; B is untouched.Five pairings at η = 0.5 compound to ~97% depression per trained synapse. A's MBON response falls from 3,700–4,300 spikes to 0–57 across three seeds; B stays at 3,400–4,300. The spike readout uses a ×20 efficacy correction on KC→MBON synapses; the synaptic-trace readout needs none and shows the same picture. We cannot watch this fly walk to a T-maze arm here (the navigation demo does that), so the decision cells' response stands in for behavior. Sensitivity in the report. Smells that partly resemble A are partly suppressed — that is the wiring's doing, not the rule's.Probe odors sharing 67/50/33/0% of A's receptor classes inherit graded suppression (~60–75% at 67% overlap, falling to 0 at disjoint), because they share memory cells and therefore share the turned-down knobs. The synaptic-trace version of this gradient needs no tuned parameters at all. It is the qualitative signature of generalization gradients in real flies.
Appendix · the assumptions ledger
For the technically inclined: every place the model is a cartoon of the biology, and why it matters.
| Aspect | Real fly | This model | Consequence |
|---|---|---|---|
| Synaptic weight | Conductances, receptor content, short-term dynamics | Synapse count × predicted transmitter sign (Shiu 2024) | Crude proxy; underlies the readout-gain caveat below |
| Substrate stability | Stable via neuromodulation, gap junctions, adaptation — none in the wiring diagram | Four structural edits: DAN fast outputs → 0; KC→KC → 0; ORN afferents input-only; excitatory AL local-neuron outputs → 0 | The substrate needed surgery before learning was testable — a finding about connectome models, not flies |
| Dopamine's fast action | DANs also make fast synapses (co-transmission) | Zeroed (edit above); dopamine acts only through the scripted rule | Clean separation, but neuromodulation exists only where we wrote it in |
| Update dynamics | Continuous, receptor-mediated; sign and size depend on odor–dopamine timing at sub-second resolution (Handler 2019) | One batch multiply between 0.5 s episodes; coincidence = "same episode" | Timing-dependence (forward vs. backward pairing) cannot emerge |
| Dopamine signal | Compartmentalized: 15 compartments, each DAN type writing to its own MBON zone, opposite valences in parallel (Aso 2014, Cohn 2015) | One scalar gate — mean PAM rate ≥ 1 Hz — and one uniform η for all KC→MBON synapses | No appetitive/aversive asymmetry, no parallel memory traces |
| Direction of change | Bidirectional: depression and recovery; memories decay and extinguish | Depression only, permanent | Extinction, forgetting, re-learning out of scope |
| Reward pathway | Sugar sensing recruits PAM DANs through circuitry | PAMs driven directly at 60 Hz — the connectome's own sugar→PAM route is silent in this LIF regime | Mirrors optogenetic conditioning, a real paradigm — but the natural reward path is not demonstrated |
| Behavioral readout | MBON compartment balance → downstream motor bias | MBON spike counts, with a ×20 efficacy correction on KC→MBON synapses; the synaptic-trace readout needs no correction | Headline % depends on readout choice; the parameter-free trace shows the same gradient |
References
- Tully & Quinn (1985). Classical conditioning and retention in normal and mutant Drosophila melanogaster. J Comp Physiol A. doi:10.1007/BF01350033
- Heisenberg (2003). Mushroom body memoir: from maps to models. Nat Rev Neurosci. doi:10.1038/nrn1074
- Claridge-Chang et al. (2009). Writing memories with light-addressable reinforcement circuitry. Cell. doi:10.1016/j.cell.2009.08.034
- Aso et al. (2014a). The neuronal architecture of the mushroom body provides a logic for associative learning. eLife. doi:10.7554/eLife.04577
- Aso et al. (2014b). Mushroom body output neurons encode valence and guide memory-based action selection. eLife. doi:10.7554/eLife.04580
- Cohn, Morantte & Ruta (2015). Coordinated and compartmentalized neuromodulation shapes sensory processing. Cell. doi:10.1016/j.cell.2015.11.019
- Hige et al. (2015). Heterosynaptic plasticity underlies aversive olfactory learning in Drosophila. Neuron. doi:10.1016/j.neuron.2015.11.003
- Handler et al. (2019). Distinct dopamine receptor pathways underlie the temporal sensitivity of associative learning. Cell. doi:10.1016/j.cell.2019.05.040
- Modi, Shuai & Turner (2020). The Drosophila mushroom body: from architecture to algorithm. Annu Rev Neurosci. doi:10.1146/annurev-neuro-062119-092917
- Bennett, Philippides & Nowotny (2021). Learning with reinforcement prediction errors in a model of the Drosophila mushroom body. Nat Commun. doi:10.1038/s41467-021-22592-4
- Dorkenwald et al. (2024). Neuronal wiring diagram of an adult brain. Nature. doi:10.1038/s41586-024-07558-y
- Schlegel et al. (2024). Whole-brain annotation and multi-connectome cell typing of Drosophila. Nature. doi:10.1038/s41586-024-07686-5
- Shiu et al. (2024). A Drosophila computational brain model reveals sensorimotor processing. Nature. doi:10.1038/s41586-024-07763-9
Back to the demo · full method and audit trail in the learning report.