python-math #26: feat(math): Q11 — replicate vectorz distance cancellation in legacy kmeans - #2654
Draft
jucor wants to merge 1 commit into
Draft
python-math #26: feat(math): Q11 — replicate vectorz distance cancellation in legacy kmeans#2654jucor wants to merge 1 commit into
jucor wants to merge 1 commit into
Conversation
This was referenced Jul 22, 2026
Draft
Draft
Draft
Draft
This was referenced Jul 25, 2026
Draft
Draft
Draft
python-math #43: docs(delphi): s7 goal state + journal — mode collapse executed, battery 20/20
#2672
Draft
Draft
Draft
This was referenced Jul 28, 2026
Draft
3 tasks
…ation in legacy kmeans ## Why Quirk Q11 (`delphi/docs/CLOJURE_QUIRKS.md`): Clojure's kmeans distances go through vectorz's `matrix/distance` on ArraySubVector row views, which computes d^2 = |a|^2 + |b|^2 - 2ab; the cancellation in that formula floors true distances below ~1e-8 to EXACTLY 0.0, so near-coincident points TIE against multiple clusters and `min-key`'s last-wins tie-break merges them into the LATER cluster (the emptied cluster is dropped). Verified in-process on the vw every-vote step-57 pair (true distance 4.66e-15 → both cluster distances 0.0 → merge), via the new cache-safe diagnostic `math/dev/proj_probe.clj`, which also reproduces the recording chain bit-exactly. ## What `_euclidean` in `legacy_kmeans.py` now uses the same formula (the module runs only in clojure-legacy mode — gated by construction). numpy reproduces the 0.0 collapse bit-for-bit on the real pair. The pre-Q11 all-singletons expectation in `test_base_cluster_lineage.py` pinned Python's old difference-based distance, not Clojure — updated to the verified contract (merges only ever happen at Q11-distance 0.0). ## Testing TDD: RED on the real step-57 pair (unit + warm-start merge integration). commit-id:7ae9c688
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Quirk Q11 (
delphi/docs/CLOJURE_QUIRKS.md): Clojure's kmeans distances go through vectorz'smatrix/distanceon ArraySubVector row views, which computes d^2 = |a|^2 + |b|^2 - 2ab; the cancellation in that formula floors true distances below ~1e-8 to EXACTLY 0.0, so near-coincident points TIE against multiple clusters andmin-key's last-wins tie-break merges them into the LATER cluster (the emptied cluster is dropped). Verified in-process on the vw every-vote step-57 pair (true distance 4.66e-15 → both cluster distances 0.0 → merge), via the new cache-safe diagnosticmath/dev/proj_probe.clj, which also reproduces the recording chain bit-exactly.What
_euclideaninlegacy_kmeans.pynow uses the same formula (the module runs only in clojure-legacy mode — gated by construction). numpy reproduces the 0.0 collapse bit-for-bit on the real pair. The pre-Q11 all-singletons expectation intest_base_cluster_lineage.pypinned Python's old difference-based distance, not Clojure — updated to the verified contract (merges only ever happen at Q11-distance 0.0).Testing
TDD: RED on the real step-57 pair (unit + warm-start merge integration).
commit-id:7ae9c688
Stack: