# Teaching a connectome-constrained model to face a Habr article

## The claim and the task

This demonstration trains a numerical neural model constrained by MaleCNS
wiring to turn a tethered simulated fly toward an intact Habr article viewport.
The alternative screen contains the same source pixels rearranged into tiles.
The model receives pixels, and its computed neck-neuron activations drive a
mechanical head controller. This is a deliberately small visual-choice task.
It does not demonstrate reading comprehension, general Habr recognition, or
subjective enjoyment.

The successful development candidate is a **differentiable rate graph**, not
the earlier leaky integrate-and-fire model. Its values are dimensionless
activations, not spike counts, firing rates, or dopamine concentration. This
distinction must remain visible in both the article and video captions.

The completed reserved test produced the following results:

| Model | Correct static choices | Article-facing time | Control-facing time |
|---|---:|---:|---:|
| Original rate-model factors | 6/12 | 0.0% | 0.0% |
| Shuffled training reward targets | 6/12 | 20.3% | 16.2% |
| Trained preferred-action targets | 12/12 | 94.7% | 0.0% |

Facing percentages average four three-second closed-loop trials: two viewports
and both screen arrangements. Static tests use those viewports at three angles,
giving twelve observations. These observations are correlated views of one
article; the table is not a population-level estimate of general recognition.
With both screens replaced by identical uniform-gray input, all three models
score 6/12. The trained model's gray-input scores differ by less than 0.000002
across identical inputs evaluated together, consistent with floating-point
rounding rather than access to hidden screen labels.

## Why the implementation changed

We first reused the spiking machinery from
[fly-wirehead](https://github.com/mattyhempstead/fly-wirehead), retaining the full
prepared graph. We tested dopamine-associated plasticity on existing synapses,
first in the inherited alpha1 circuit and then with a PAM01-gated depression
rule. Paired and unrelated reward did not yield the required learned preference.
Changing existing inputs to neck-motor cells also failed the full-network checks.

The failure was not fixed by pretending that a dopamine electrode was evidence
of liking. We examined the visual signals reaching the proposed output pathway.
A larger observation set and longer exposures still did not provide a strong
readout from those frozen inputs. This motivated training across the graph
instead of limiting optimization to a small output circuit.

The resulting rate model is a new engineering model of the same wiring. This
is a substantive change in equations and training method, not a faster version
of the spiking physiology. The failed experiments remain documented in
READING_STATION_PROGRESS.md and READING_STATION_METHODS.md. The old videos cannot
be relabeled as recordings of the new trained model.

## What comes from anatomy

The prepared MaleCNS v1.0 graph contains 166,700 nodes, 25,582,938 directed
neuron-pair edges, and 124,177,617 represented synaptic contacts. Several
contacts can belong to one edge. The original downloaded files and prepared
arrays were checked against the upstream checksum locks. No small selected
circuit replaces the rest of the graph during evaluation.

Cell annotations identify the retinal inputs and the two output pools of 22
annotated neck-motor neurons each. Soma coordinates are available for 139,662
nodes. Spatial visualizations omit the other positions rather than inventing
coordinates; those nodes are still simulated.

The original graph preparation and visual mapping come from the pinned
fly-wirehead revision `fcefe9441f80e25aab713411ebced53f5e5ea172`. Body geometry
comes from the pinned FlyBody assets, revision
`d015e9bfe441bd90ae431bac24c55cb74bdbce26`. The wiring data, body assets and copied
code retain their respective upstream licenses and attribution.

## What the model sees

Three captures show different scroll positions of
[one real Habr article](https://habr.com/ru/articles/1079104/). Each is resized to
640×360 pixels. The control divides this image into a 12×16 grid and permutes
all 192 tiles. This preserves all source RGB pixels, although subsequent
perspective projection and resampling affect the retinal pixel distribution.

Two screens stand at depth 1, centered horizontally at −0.135 and +0.135, each
with half-width 0.105. A camera with a 0.5 rad horizontal field of view rotates
with the simulated head. The rendered view is BOX-resampled to 160×90 pixels.
An image therefore changes when the head moves, even though the page itself
does not scroll during a trial.

The adapter samples linear-sRGB luminance at 3,335 mapped R1–R6 positions and
green or blue intensities at 811 mapped R8 positions. It does not perform OCR,
query the page DOM, look at URLs, recognize filenames, or call a separate image
classifier. Unmapped receptors receive no fabricated optical input. The
coordinate and color mappings are inherited display proxies, not a calibrated
measurement of a biological compound eye.

Unlike the previous spiking adapter, this model uses linear intensities without
the inherited saturating current transformation or constant lamina bias. The
inherited R8→aMe12 sign correction is present before task training. These are
declared modeling choices.

## The equations and trainable quantities

Let `W[j,i]` be the original signed weight from source node `i` to receiving
node `j`. First normalize by the receiving node's total absolute input weight.
Then train two log factors per node, `pre[i]` and `post[j]`:

```text
effective_W[j,i] = 2 × W[j,i] / max(sum_k abs(W[j,k]), 1)
                   × exp(pre[i]) × exp(post[j])
```

Both factors start at zero, corresponding to multipliers of one, and are
bounded to [−3,+3]. The normalization and factor 2 are fixed engineering
settings. Positive multipliers preserve every existing edge's sign and cannot
create a new edge. There are 333,400 factor parameters, shared across edges;
this is not 25 million independently learned edge parameters.

For each image, start with zero activity and perform 24 recurrent updates:

```text
h_next = 0.5 × h + 0.5 × tanh(effective_W @ h + visual_input)
```

The carry-over term is numerical state dynamics, not a newly inserted anatomical
synapse. Activities lie between −1 and +1. There are no membrane voltages,
refractory periods, spike timestamps, neurotransmitter-release concentrations,
or validated biological time constants in this rate model. A negative activation
does not mean a neuron fires at a negative frequency.

The fixed output score is:

```text
score = 100 × (mean(h[left_neck_pool]) − mean(h[right_neck_pool]))
```

A positive score requests a rightward turn and a negative score a leftward
turn. The score formula is fixed before training. A class label does not enter
this computation at evaluation time.

## Reward and optimization

Earlier forced-choice probes tested looking toward each screen, with an
explicit artificial training electrode stimulating the annotated PAM11 cells
for the rewarded choice. The measured returns supplied preferred-action
targets. The rate-model optimizer uses those targets as supervised labels.
It does **not** simulate a validated dopamine-gated learning mechanism. In
particular, the successful rate training must not be attributed to the failed
spiking plasticity rules.

Training uses Adam, learning rate 0.03, batches of eight, 300 updates, seed
20260912, a binary cross-entropy loss on the directional score, and a small
penalty on squared log factors. The original anatomical weight pattern is the
starting point; no trained checkpoint from the abandoned website-classifier
experiment is loaded.

The training set contains 216 observations: three viewports, 12 independently
permuted controls, two screen arrangements and three viewing angles. Validation
contains 54 observations with three other permutations and angles −0.09, 0 and
+0.09 rad. The article itself is shared. These are not 270 independent articles.

All 300 updates run before model selection. The checkpoint with the lowest
validation cross-entropy is selected; for the paired run it is update 250.
The original untrained factors are the baseline. A second 300-update run uses
shuffled training targets, with the same minibatch sampling sequence and other
settings. Its own checkpoint is selected by the same validation rule.

The previously reserved test observations use a separate tile-permutation seed
and were excluded from fitting and model selection. Because their article
viewports were seen during training, a successful test supports this narrow
page-layout preference, not recognition of unseen Habr articles.

## How activity moves the body

At each 20 ms control boundary, the program renders the current view, evaluates
the frozen rate graph, and passes its score to a fixed controller. An 80 ms
low-pass filter conditions the score. The requested angular velocity is
`0.8 × tanh(filtered_score)` rad/s, with a command-acceleration limit of
8 rad/s² and commanded yaw bounded to ±0.19 rad.

MuJoCo advances the tethered FlyBody under that actuator command. The actual
joint angle, including the mechanical model's limits, determines the next
viewpoint. The thorax remains fixed and other actuators retain rest commands.
This is a head-orienting demonstration, not a learned walking or scrolling
behavior. The neuron-to-actuator controller is an engineered interface, not a
recovered biological neuromuscular mapping.

The rate network is reevaluated from zero for each image; the head controller
and mechanical state persist through the trial. Its 24 internal updates are
computational steps, not 24 measured biological timesteps. The body has a
physical simulation clock, but the neural activations do not acquire biological
time constants merely because the two systems are connected.

The previous violent neck motion had a concrete mechanical cause. Tethering
changed automatic parent–child collision filtering, so overlapping attachment
geometries repelled one another. Explicit thorax/direct-child exclusions restore
the intended filtering. The model must pass a zero-command settling check before
running. No head trajectory is cosmetically smoothed after simulation.

## Evaluation and interpretation

A three-second trial begins with the head in its settled neutral pose. Article
facing is defined in advance as an actual yaw within 0.055 rad of the article
screen's ±0.135 rad bearing. The corresponding interval around the other screen
measures control facing. The initial turning interval counts against the facing
fraction. All evaluation weights are frozen and no reward electrode is active.

Static classification and closed-loop behavior are separate tests. Passing the
first does not guarantee the second because turning changes the pixels. A
swapped-screen trial checks that the same trained graph reverses direction when
the article changes sides. Baseline and shuffled-target runs help distinguish
learning from a preexisting bias or an action built into the controller.

The developmental closed-loop result was also 94.7% article-facing time and zero
control-facing time in all six validation trials. Mechanical saturation makes
the successful left and right trajectories very similar across viewports;
that is a consequence of the fixed controller and its bounds, not an authored
animation. The simulation must not be given artificial jitter just to make it
look more alive. The controller also filters occasional wrong-sign scores during
the initial turn; a successful movement does not mean every intermediate neural
decision is correct. The trained head settles at approximately ±0.1455 rad
(±8.3°), near the mechanical model's joint limit, rather than indefinitely turning.

Even a clean held-out result would establish only a visual preference of this
engineered system. It would not show that the original animal has been uploaded,
that the model understands the article, or that an inner experience of enjoyment
has been measured. “Likes reading Habr” can be a playful shorthand if the article
states the operational definition and limitations plainly.

## Reproduction and presentation

The development source package preserves the `work/` layout, copied upstream
code, source locks, three screenshot captures, mechanical assets and attribution.
The large graph download and local Python/CUDA toolchain are separate. The
tested environment uses Python 3.11, PyTorch 2.6.0 with CUDA 12.4 and a GTX 1080 Ti.
It is a local Windows development snapshot, not a verified cross-platform
one-click installer.

The main scripts are `train_rate.py --fast`, its `--unrelated` control,
`rate_closed_loop.py --condition ...`, and the rendering/evaluation scripts
included alongside them. The slower native-backpropagation implementation and
the cached-transpose implementation agree to below 1e-6 in the checked outputs
and gradients. Caching the fixed transpose changes execution cost, not the
neural equations. Training checkpoints include optimizer and random-generator
state for resumption.

The comparison video shows the first reserved viewport with both screen
arrangements in all three conditions. Each recorded 20 ms boundary occupies one
frame at 25 fps: playback is twice slower than physical simulation time. The
joint positions are replayed without interpolation or postprocessing. The
displayed input is the image used before that interval's neural evaluation and
motor update. The Russian captions explicitly identify conditional activations
instead of spikes. Yellow and blue represent positive and negative values, with
one fixed square-root brightness transformation across conditions. Overlapping
soma pixels show the strongest signed magnitude; unknown positions are omitted.
The PAM11 readout is the actual mean activity of those annotated nodes, not a
reward electrode, dopamine concentration, or measure of pleasure.

The tested implementation, selected checkpoints and generated files are recorded
with hashes. The source archive is a development/reproduction package; it does
not include the large original connectome download or a Python environment.
