| # Tangled Closed-Loop Counting |
|
|
| ## Goal |
|
|
| Render a tangle of smooth **closed loops** on a single canvas. Every |
| loop is drawn in the **same** dark colour, so the model cannot recover |
| the count by colour-segmenting the image. Loops cross each other and |
| themselves freely, but never run parallel for long stretches — every |
| loop remains individually traceable. |
|
|
| This is a *distributed scanning* task: there is no single starting |
| point. The model must look across the whole image, follow each loop |
| all the way around, and report how many distinct closed loops exist. |
|
|
| ## Differs from `sequential_traversal/tube_connection` |
|
|
| `tube_connection` labels endpoints and asks "which top label connects |
| to which bottom label", which is solved by tracing one path at a time. |
| Here there are no labels, no endpoints at all, and no per-loop tracing |
| question. The model needs the global *count* of distinct closed loops. |
|
|
| ## Differs from `sequential_traversal/line_intersections` |
|
|
| `line_intersections` uses perimeter-anchored open curves and asks for |
| crossing sequences along one labelled string. Here every curve is a |
| closed loop (no endpoints anywhere), every loop is anonymous, all in |
| the same colour, and the only ground truth is the number of loops. |
|
|
| ## Question |
|
|
| > How many distinct closed loops are tangled together in this image? |
| > Each loop is a single continuous curve that closes back on itself — |
| > there are no loose endpoints anywhere. All loops are drawn in the |
| > same colour and may cross other loops or themselves freely. Count |
| > the total number of distinct closed loops and report the count as a |
| > positive integer. |
|
|
| ## Generation Procedure |
|
|
| 1. **Sample N** in `[min_loops, max_loops]` (default 5–11). |
| 2. **For each loop**, build a smooth closed curve: |
| - Pick a random interior centre so the loop fits inside |
| `interior_margin` (default 55 px) of the canvas edge. |
| - Sample 6–10 waypoints on a jittered ring around that centre |
| (angle jitter ≈ 0.42 rad, radius jitter ≈ 32 % of the mean |
| radius, mean radius sampled from 150–275 px). |
| - Fit a periodic cubic B-spline through the waypoints |
| (`scipy.interpolate.splprep(..., per=True, k=3)`) and |
| dense-sample 900 points along it. The last point is snapped to |
| equal the first so the renderer draws a genuine closed curve. |
| 3. **Find all crossings** (self and pair) — used only by the |
| close-approach validator below. |
| 4. **Reject** the sample if any two curves come within ~9 px of each |
| other anywhere except at a real crossing point. For self-closeness |
| the segment-index gap is computed **circularly** (with wraparound), |
| since closed curves have no linear endpoint ordering. |
| 5. **Render** all loops in the same dark colour onto an off-white |
| canvas with subtle background noise. |
| |
| ## Anti-Shortcut Notes |
|
|
| The task has been through two shortcut-plugging rewrites: |
|
|
| 1. **Unique-colour shortcut → single stroke colour.** An earlier |
| version assigned each string a unique colour, collapsing the task |
| to "count distinct colours". Fixed by drawing every curve in the |
| same dark colour. |
| 2. **Skeleton-endpoint shortcut → closed loops.** The previous |
| perimeter-anchored design had each string as an *open* curve with |
| two endpoints on the border. A ten-line attack recovered the |
| answer on 28 / 30 samples: `skeletonize(gray < 110)` → |
| count pixels with exactly one 8-neighbour → divide by two. |
| Crossings are X/T junctions (degree ≥ 3), so only the two terminal |
| endpoints of each string have degree 1, and endpoints ÷ 2 is the |
| string count. Moving to closed curves eliminates the attack |
| entirely — a closed loop's skeleton has no degree-1 pixels, so the |
| attack returns 0 regardless of loop count. Verified on the |
| regenerated dataset. |
| 3. **No-near-parallel validation** (retained) prevents two loops that |
| run parallel for a long stretch from reading as one fat loop, |
| which would also confuse a human counter. |
|
|
| ## Annotation Format |
|
|
| ```json |
| { |
| "image": "images/tangled_loops_00000.png", |
| "width": 1024, |
| "height": 1024, |
| "num_loops": 7, |
| "question": "How many distinct closed loops are tangled together ...", |
| "answer": 7 |
| } |
| ``` |
|
|
| ## Output Organization |
|
|
| ```text |
| tangled_loops/ |
| creation.py |
| creation.md |
| annotations.jsonl |
| data.json |
| images/ |
| tangled_loops_00000.png |
| ... |
| ``` |
|
|