This is a genuine 2D counterpart to the 3D MERFISH simulator, not a flattened version of it. The 3D scene scatters molecules at arbitrary tissue coordinates that have nothing to do with the barcode math. This 2D model instead visualizes the code space itself: it takes the real pairwise Hamming distances between the codebook's error-correcting barcodes and embeds them into a 2D plane by classical multidimensional scaling (MDS) — an eigendecomposition of the double-centered squared-distance matrix, computed live with a Jacobi rotation solver.
Double-centered Gram matrix: B = -½ J D² J, J = I - (1/k)·11ᵀ
Eigendecomposition: B = V Λ Vᵀ (Jacobi sweeps)
2D codeword coordinates: X_i = (√λ₁·v₁ᵢ, √λ₂·v₂ᵢ)
New molecule (Gower interpolation from its noisy readout):
b_i = -½(d²ᵢ - rowMean_i - mean(d²) + grandMean)
z_m = (b · v_m) / √λ_m
Each round still reveals one bit of every molecule's observed barcode, exactly as in the 3D version — and decoding still runs the identical nearest-codeword algorithm on the true N-bit Hamming distances (error correction accepts a single-bit mismatch when it is unambiguous). What's different is where a decoded molecule ends up drawn: its exact vector of Hamming distances to every codeword is projected into the same 2D plane as the codewords themselves, using the closed-form Gower out-of-sample formula above — the same trilateration principle real positioning systems use to place a point from distance measurements to fixed anchors.
- Barcode length N — more rounds mean a larger, more separated codebook; also changes the code-space geometry MDS has to compress into 2D.
- Bit-error rate — models real dropout from incomplete probe binding, photobleaching, or segmentation noise; pushes a molecule's projected point away from its true codeword.
- Error correction toggle — off, only an exact bit-for-bit match decodes; on, the nearest codeword within 1 bit is accepted, exactly as real MERFISH pipelines do.
- Embedding stress — a real diagnostic (Kruskal stress-1): how much geometric distortion 2D compression introduces versus the true Hamming distances. It is expected to be small but nonzero, since an N-bit Hamming cube generally cannot be embedded exactly in 2 dimensions.
Real-world relevance: this is how coding theorists and computational biologists actually visualize high-dimensional barcode spaces — MDS plots of codeword geometry are a standard diagnostic for how separable, and therefore how error-tolerant, a combinatorial barcoding scheme really is.