# MaleCNS: an image-choice experiment in the browser

The site runs the full 166,700-node / 25,582,938-edge signed rate graph in a
dedicated browser worker. WebGPU is preferred when available; WebAssembly is
the CPU fallback. The VDS serves static files only. Image pixels, neural
inference, controller state and MuJoCo physics stay on the visitor's device.

## Numerical model

This is the selected `iteration-0250.npz` rate-model checkpoint from the article
experiment, not the abandoned spiking prototype. Every original edge remains.
Exported CSR weights are transposed to receiving-neuron rows and normalized by
the absolute incoming weight sum exactly as in `RateGraph`. Learned positive
pre/post gains preserve edge signs. Each image starts at zero state and runs
24 updates: `h = 0.5*h + 0.5*tanh(2*post*(W @ (h*pre)) + drive)`.
The output is 100 times the difference between the mean states of the 22 left
and 22 right annotated neck motor neurons. Initial-weight mode sets gains to 1.

Images are decoded locally, composited on white, and resized using the Pillow
BOX rule to 640×360. The 192 equal 40×30 tiles are permuted with a recorded
xorshift32/Fisher–Yates seed. No pixels are invented. A perspective projection
of the two screens is computed at the current measured head angle and BOX
reduced to 160×90. Receptor sampling and sRGB-to-linear conversion match the
Python adapter. No URL, filename, OCR, image classifier, screen-label score,
or hard-coded target preference enters the neural function.

The output drives the same filtered velocity/position controller as the video.
Only the head-abduction actuator is commanded. The original FlyBody model is
tethered, preserves its attachment collision exclusions, and uses MuJoCo 3.13
implicitfast integration in 200 × 0.1 ms steps per 20 ms control interval.
The browser renders measured joint poses. The golden line is a schematic
head-bearing guide, not a biological visual field. Simulation time advances
only when a new neural calculation and physical step finish; speed depends
on the device. The separately displayed compute time measures projection and
neural inference, excluding downloads and physics/render overhead.

The activity plot preserves XY coordinate proportions for the spatial head
crop Z < 60000. Color is a fixed signed state scale with
`asinh(abs(h)/0.01)/asinh(100)` brightness. Overlapping somas use the strongest
absolute state. Activity is dimensionless, not spikes or dopamine.

## What this does and does not establish

The site genuinely recomputes outputs for supplied pixels. Its checksummed
weights, readable JS/WGSL/C++ code, optional initial-weight mode, screen swaps,
new shuffles and downloadable input/output logs make the calculation inspectable.
This is not a proof of accurate fly physiology or pleasure. Training used
multiple views of one Habr article, not broad Habr recognition. Arbitrary
uploaded images can produce different or incorrect preferences, including a
preference for fragments. There is no fallback that forces the desired choice.

## Checks

`test_numerics.mjs` compares all 43,200 input bytes, receptor drive and all
166,700 states against three Python fixtures. The checked projections are
byte-for-byte identical; measured WASM errors are in `numerical-validation.json`.
`test_physics.mjs` replays 50 recorded controller outputs and compares every
joint coordinate with Python. `test_browser.mjs` checks actual browser execution,
screen swaps, initial weights, uploads, journal downloads, mobile layout and
network methods. A browser self-check against a Python state fixture runs before
enabling experiments. GPU states/output must agree within 0.002 absolute error;
otherwise it tries the CPU backend. NaN/nonfinite results cannot pass.

Optional WebMCP read/step tools reuse the visible experiment state when the
browser supports the API; unsupported browsers use the ordinary controls.

## Reproduction in the existing workspace

Use `work/venv/Scripts/python.exe -X utf8` for Python scripts. First run
`export_model.py`, `build_kernel.py`, `export_fixtures.py` in this directory.
The sibling `reading-station`, `habrfly`, `emsdk`, `flybody` and `mujoco-web`
directories are required. The pinned local Emscripten SDK is 6.0.9.
Then serve `dist/` with any static HTTP server. Production requires HTTPS;
localhost is also a browser secure context. No inference service is needed.

`node test_numerics.mjs` checks WASM. Browser tests use the locally installed
Playwright package under `test-tools/` and Chrome on this Windows workstation.
The optional `TEST_URL` environment variable targets the published site.
No credentials or live server configuration are included in the public source.

## Attribution

MaleCNS v1.0 connectivity and metadata: the MaleCNS collaboration / Janelia,
CC BY 4.0, https://male-cns.janelia.org/download/ . The upstream pixel mapping
and graph preparation are derived from fly-wirehead and stonkfly, with retained
MIT notices. Original project: https://github.com/mattyhempstead/fly-wirehead .
This browser rate implementation is a different model from its LIF application.
FlyBody and MuJoCo: Google DeepMind, Apache 2.0. Three.js: MIT.
The supplied sample screenshots come from https://habr.com/ru/articles/1079104/ ;
the article and site artwork retain their respective owners' rights.

Full license notices are provided under `source/licenses/` on the site.
