Repository navigation
perf(color): solve the balanced color assignment as a transportation problem - #73
Conversation
Adds the old slot-expansion implementation as a test-only reference and checks equal minimum cost, capacities, pins and (for unique optima) equal assignments for sizes 2..10, plus exact-tie cases and a speed budget at n=12 and n=15. The vision adapters now re-export balancedAssign and clusterDistance for it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The slot expansion made an M x M matrix with M = 6 n^2 and solved it in O(M^3), so the six-face pass took 2.3 s at 7x7 and 74 s at 15x15. Points now enter one by one along the cheapest augmenting path over the six clusters, which keeps the same minimum cost and capacities at O(m^2 k). Equal costs resolve by the lowest cluster and member index. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
clusterDistance converts both colors on every call. balancedAssign now converts points and centroids once, and splitMixedPairs converts the members once for its farthest-pair search (the distance is symmetric, so only pairs at or after the diagonal are visited). Values and the pair chosen are unchanged. Adds a learning-pass budget at 15x15. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Review: CLEAR head=b51190e4eab643ce3e213c92227ab87d12d345e5 patch-id=6df60e408b0f6fad4b2e2c4364b162e106f8c4f9 pr=73 |
Speeds up the six-face color pass (
classifyAcrossFaces) for large cubes. Per-face color reading is untouched.Cause:
balancedAssignexpanded each of the six colors intocapacityslots and solved an M x M matching (M = 6 n^2) with the O(M^3) Hungarian algorithm, 20 times inkMeansClusterplus 17 more calls. The farthest-pair search insplitMixedPairsconverted both colors to Oklab on every distance call.Changes:
balancedAssignis a transportation problem over the six clusters (cheapest augmenting paths, O(m^2 k)). Same objective (sum ofclusterDistance), capacities and pin rules;hungarianAssignmentstays.balancedAssign,splitMixedPairs); values are unchanged.Tests:
test/balancedAssign.test.tskeeps the old slot expansion as a reference: equal minimum, capacities, pins, equal assignment for unique optima (2..10), speed budgets at n=12/15.Equivalence:
classifyAcrossFaceson synthetic cubes (random, solved, checker; real and clean presets) returns a byte-identical result before and after for n=2..12 (72 of 72 cases).Time, median of two cubes under load 25-35: 7x7 913 -> 197 ms, 9x9 1.9 s -> 0.31 s, 12x12 11.0 s -> 0.34 s, 15x15 51.8 s -> 0.50 s.
Tie behavior: with exactly equal costs (coarse color grids) the minimum is equal but another equal-cost assignment can be chosen (the reference differs in about two thirds of 400 such cases); real captures and the synthetic cubes above are not affected.
Checks: typecheck, lint, format:check, build, typos,
git diff --check, vitest (47 known LFS failures; nothing else fails when the load allows the 5 s timeout).Blocker: none.
🤖 Generated with Claude Code