AI & neural simulation
FlyBrain
An ongoing Python/PyTorch project with a learned 2D approach-and-stop controller and a separate 3D anatomical neural viewer.
Why I started
I wanted to understand how sensory signals become decisions and learn PyTorch by building an embodied system.
My contribution
I connected sensing, a spiking neural model and a learned motor readout, evaluated the 2D controller, and built a separate anatomical viewer.
Current state
The frozen 2D approach-and-stop assay reached 63/64 successes. Learned 3D landing remains incomplete; the anatomy display shows a modeled subset.

The question
Could a simulated fly find food and stop using sensory signals, rather than a supplied map or target bearing? I chose this project to learn PyTorch and machine learning through an embodied system.
What I built
The 2D app connects bilateral odor sensing, a spiking neural model and a learned speed/turn/stop readout. Its current frozen candidate contains 83 sourced BANC cells and two explicitly engineered food-contact cells. The controller receives sensory signals, without world coordinates or a supplied target bearing.
A separate Panda3D lab brings together simulated flight physics, sourced anatomical geometry, live spike coloring, pathway inspection and deterministic replay. Its 589-cell circuit and 4,139 anatomical edges are a modeled subset, not a whole-brain reconstruction.
Training and evaluation
A 1,500-update supervised fit changed 419 readout parameters. The neural graph and neuron rules stayed fixed. I checked gradients, parameter changes and save/reload consistency before evaluating behavior.
The recorded frozen final 2D recovery assay achieved 63/64 full-task successes, compared with 0/64 for each matched untrained and fixed decoder. Episodes lasted 20 seconds; success required food contact, slowing, an exact stop and sustained stationary contact. One trained case failed.
- Results apply to the recorded environment and start distribution.
- This approach-and-stop result is distinct from historical synthetic and arrival-only experiments.
- Only the motor readout was trained; this was not whole-connectome training or reinforcement learning.
The 3D anatomy and flight lab
The Panda3D viewer shows sourced neuron branches in anatomical context, with separate cameras for the fly and the neural anatomy. You can rotate, pan and zoom, inspect a selected neuron, show its connections, filter activity classes and reveal the ventral nerve cord. The full brain outline provides context around the modeled subset; it does not mean every neuron is simulated.
In a fly, the ventral nerve cord connects the brain to circuits involved in body and motor control. The gallery includes front and oblique views of both regions, plus the fly resting on a flower. In that flower demonstration, a hand-written sensory teacher supplies flight commands while the neural circuit receives observations and displays activity.
Learned 3D landing remains incomplete. A separate turn-and-flee experiment progressed to a 48-case physical-flight validation, but failed its declared acceptance gate: 19 of 24 intact cases met the full completion criteria, with recovery and boundary-collision failures remaining. It was not promoted to a validated default. These experiments do not establish reliable neural predator avoidance.
How I worked
I used AI-assisted development alongside seeded runs, matched controls, interventions, pytest, persistent project logs and recorded experiments. The simulator connects sensing, neural state and movement in a closed loop: each action changes what the fly senses next.
The early synthetic network and an earlier arrival-only assay were useful development stages, but they asked different questions. The final approach-and-stop result adds actual food contact and sustained stopping, so I keep those experiments separate. This work has developed my understanding of autograd, supervised learning, dynamical systems, control, visualization and reproducible evaluation.
- Next: complete and independently evaluate the 3D landing work.
- Continue live-review checks and preserve the provenance of every new result.