Johanna P. Müller

2026 Methods

Edges, Klein Bottles and Written Weights

9 min read convolution · topology · interpretability · weight-space-programming

The inspiration for this blog post came in the form of two half-remembered things: a JMLR paper on Klein bottles in convolutional layers, and the Sobel filter, which I remember from teaching medical engineering exercises at FAU, where it was often the first kernel that students would code manually using JAVA. When I co-authored the following paper in which a language model writes CNN weights without seeing any images, it hit me that all three are, in fact, producing the same kernels, and this is because of one short piece of algebra.

Hand-designed Filters

Sobel x:  -1  0  1        Laplacian:   0  1  0
          -2  0  2                     1 -4  1
          -1  0  1                     0  1  0

Sobel x subtracts the left column of a 3×3 patch from the right, with the middle row counted twice. It’s a finite-difference first derivative, large wherever there’s an edge. The Laplacian estimates the second derivative summed over both directions, and responds to thin lines and blobs.

A small synthetic cross-section, a bright ring around a darker centre with a thin line and a small dot, next to the output of six classic edge operators. Top row, first-derivative operators: Roberts (1963), Sobel (1968) and Prewitt (1970) each outline the ring. Bottom row: the Laplacian and the Marr-Hildreth Laplacian of Gaussian (1980) respond most strongly to the thin line and the dot, and Canny (1986) returns thin, connected edge curves.
Classic edge operators on a 40×40 synthetic cross-section, with each operator's kernels drawn above its output. Top: first-derivative operators, shown as edge strength √(gx² + gy²). Bottom: second-derivative operators (mid-grey is zero) and Canny's thin, linked edges.

Every weight has a reason. What hand-design can’t tell you is where to stop: there are infinitely many angles, widths and mixtures, and nothing says which ones images need.

The Klein Bottle

That question was answered from the data side. Lee, Pedersen & Mumford (2003) found that high-contrast 3×3 patches of natural images aren’t spread out in their 9-dimensional space but concentrate on low-dimensional nonlinear structures. Carlsson et al. (2008) used topological data analysis to show that the shape of the densest part is a Klein bottle. Love, Filippenko, Maroulas & Carlsson (2023) write it as a formula in two angles:

u = x·cos θ₁ + y·sin θ₁
F(θ₁, θ₂)(x, y) = sin θ₂ · u  +  cos θ₂ · (2u² − 1)

θ₁ is the orientation. θ₂ = π/2 leaves the ramp u, an edge, and θ₂ = 0 leaves the parabola 2u² − 1, a line. Values in between give mixtures of the two. Rotating by 180° flips the edge but not the line, so F(θ₁ + π, θ₂) = F(θ₁, −θ₂), and that twist is what makes the surface a Klein bottle rather than a torus. Every point on the surface below is one filter.

The interactive figure needs JavaScript to draw the bottle and its filters.

Hover over the bottle (or tap it) to see that point's 3×3 filter and its continuous patch; drag to rotate. Teal marks edges, yellow marks lines, and the colours blend in between.

Love et al. use these patches as a frozen first layer. Their networks need far fewer images, and they report about 30 % accuracy generalising from MNIST to SVHN, where a plain CNN scores the 10 % of chance.

Connection

A table of 3 by 3 filters. Columns: a diagonal edge bright to the upper right, a diagonal edge bright to the upper left, a bright diagonal line, and a centre-surround filter. Rows: textbook kernels (Prewitt diagonals, the line-detection mask and the 8-neighbour Laplacian), the matching Klein bottle points, the filters Claude Opus 5.5 wrote for SynthUterus (the two diagonal edges only), and the filters GPT-6 Astra wrote (all four). Within each column the four filters show the same pattern.
One kind of filter per column, from three sources. The LLM rows are the actual weights from each model's first SynthUterus call (released with the paper). Klein bottle filters are shown with their mean removed, like the textbook kernels. Black is negative and white is positive, each filter scaled to its own maximum.

Average the edge at θ₁ = 0 over a 3×3 grid and every row reads -1 0 1. That’s the Prewitt operator, and Sobel is the same with the middle row weighted twice. Every edge kernel at any angle sits on the bottle’s edge circle. The Laplacian adds the second derivative across x to the second derivative across y, the two quantities the lines at θ₁ = 0 and θ₁ = π/2 respond to. It isn’t on the surface itself, but it combines two of its directions.

This is no coincidence. A first and a second derivative are the terms of a second-order Taylor expansion, the local jet that Koenderink & van Doorn (1987) proposed as a model of early vision, and a 3×3 patch has too few pixels to say much beyond second order. Hand-design, natural-image statistics and, as Olshausen & Field (1996) showed, learning a sparse code all land on this vocabulary of oriented, localised filters. Jacobsen et al. (2016) built it into a CNN directly, learning only the weights that combine a fixed Gaussian-derivative basis. That helped most on small datasets, including 3D brain MRI, where there is no large dataset to pre-train on.

Weight-Space Programming

The idea comes from Takehi, Teoh, Zhang & Khattab (MIT CSAIL, 2026), who introduced weight-space programming: treating a network’s weights “as a program to be read and written” by an LLM, rather than leaving them entirely to an optimiser. They show LLMs reading what a network was trained on from its raw weights, writing game-playing networks for MinAtar and Go without training, and editing a small language model’s weights to fix its reasoning loops.

We carried it over to medical imaging. In Weight-Space Programming for Medical Imaging (Lindholz, Ruppel et al., arXiv 2026), we asked Claude Opus 5.5 and GPT-6 Astra to write every weight of a small CNN (ten 3×3 filters, pooling and a linear read-out) in one reply, with no data, no tools and no images. On six MedMNIST tasks the written networks beat chance everywhere (mean AUC 0.719 and 0.711) and zero-shot MedSigLIP on five, but the same network trained on 256 labels wins on all six (0.828). On SynthUterus, our synthetic pelvic MRI dataset, Opus reaches 0.764, while Astra drops to 0.136 because it looks for the cervix where the crops don’t show it. The filters are where the three ideas meet: for SynthUterus, Opus wrote four oriented edge detectors and Astra a mix of edge, line, centre-surround and identity kernels, both with a few rounded values much like Sobel’s integers. In Klein bottle terms, that is the edge circle for Opus and both circles for Astra. Trained with Adam on 117 labels, the same network learned smooth, mixed patterns instead: with that little data, gradient descent hadn’t rediscovered the vocabulary the textbook, the image statistics and the LLMs start from.

Learned, Written or Self-Rewritten

The other end of a network has a predictable shape too. Late in training, a classifier’s last layer settles into what neural collapse (Papyan, Han & Donoho, 2020) calls a simplex equiangular tight frame: one direction per class, every pair at the same angle, all as far apart as possible, like the corners of a triangle for three classes or of a tetrahedron for four. So both ends of a network are known in advance: edge and line filters at the input, an equiangular frame at the output. Gradient descent finds both when it has enough data, but with 117 labels it doesn’t get there. The alternative is to build them in from the start: Klein bottle filters at the input and, as we explore for medical imaging encoders, an equiangular classifier head at the output (Müller et al., 2026).

The layers in between have no shape we can write down in advance, so their weights have to come from somewhere. One answer is a hypernetwork (Ha et al., 2017): a second network whose output is the weights of the first. Give it a learned vector that describes the task, and it produces a network for that task; we use this to build 3D segmentation networks when there is little data (Hagen et al., MIDL 2026). Weight-space programming is the same idea with an LLM in the hypernetwork’s place: the task is described in plain language instead of a learned vector, and the LLM was never trained to write weights at all.

One step further, the writer could improve itself, and the whole loop would run without us. That is the idea behind Schmidhuber’s Gödel machine (2003): a system that can rewrite any part of its own code, including the way it learns, whenever it can prove the rewrite is an improvement. Such proofs are rarely available in practice, but the Huxley–Gödel Machine (Wang et al., ICLR 2026) approximates the idea with coding agents that edit their own code, and the best agent it produces matches the best human-engineered coding agents. Put the pieces together and every part of learning has a math/machine stand-in: geometry for the first and last layers, an LLM (or hypernetwork) for the middle, a self-improving agent for the LLM (or hypernetwork).

For now, a few hundred labels still beat our written networks on every task. But labels wouldn’t have to build a network from scratch anymore, only fine-tune one that was already written. So is training from scratch on thousands of labelled scans becoming a habit rather than a necessity? Or is a fully automated learner just a better way of hiding what it has already seen?

← All posts