fix(math): clamp subgroup-k-smoother smoothed-k to available clusterings (#2575)#2609
Open
jucor wants to merge 1 commit into
Open
fix(math): clamp subgroup-k-smoother smoothed-k to available clusterings (#2575)#2609jucor wants to merge 1 commit into
jucor wants to merge 1 commit into
Conversation
Collaborator
Author
…ngs (#2575) PR #2536 clamped smoothed-k in group-k-smoother but left the identical bug in :subgroup-k-smoother. A group's subgroup clustering runs k-means for k in (range 2 (inc M)), where M is count-based on the group's base-cluster count. When group membership drops below a /12 boundary, M falls, the carried smoothed-k can exceed M, and (get group-subgroup-clusterings smoothed-k) returns nil — an empty subgroup clustering that crashes conv-repness (cryptic ISeq error pre-#2536, or #2536's clear IAE on master). conv-update still fails. Mirror #2536's group-level clamp into the per-group subgroup smoother: if the carried smoothed-k is no longer a key in this group's current subgroup clusterings, fall back to this-k (the best available k by silhouette). Test: stale-subgroup-smoothed-k-is-clamped-to-available-subgroup-clusters in conv_edge_cases_test.clj, mirroring the group-level regression test. Full math suite: 53 tests, 150 assertions, 0 failures. Reported by lgelauff (Lodewijk), reproduced via warm-path replay across 50+ public openData conversations. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jucor
force-pushed
the
jc/subgroup-k-smoother-clamp
branch
from
July 17, 2026 01:27
ed02b20 to
207fa9f
Compare
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.
Summary
Fixes #2575. PR #2536 clamped
smoothed-kingroup-k-smoother, but the identical bug remained one level down in:subgroup-k-smoother— which #2536 did not touch. This applies the same clamp to the subgroup smoother.Root cause (same chain as #2536, one level down): a group's subgroup clustering runs k-means for
k ∈ (range 2 (inc M)), whereMis count-based on the group's base-cluster count (M = min(max-k, 2 + ⌊#base-clusters/12⌋)). The:subgroup-k-smoothercarriessmoothed-kforward across ticks (anti-flap) without clamping to the current keys. When a group's membership drops below a/12boundary,Mfalls; the carriedsmoothed-kcan exceedM;(get group-subgroup-clusterings smoothed-k)returnsnil→(map f nil)→()— an empty subgroup clustering →conv-repnesscrashes. On post-#2536master, #2536's guard turns this into a clearIllegalArgumentException("group-clusters is nil or empty"), butconv-updatestill fails — the guard makes it legible, it doesn't prevent the empty clustering.Reported by @lgelauff, reproduced via warm-path replay across 50+ public openData conversations.
Change
math/src/polismath/math/conversation.clj,:subgroup-k-smoother— mirror #2536's group-level clamp into the per-groupsmoothed-kcomputation:this-kis always a valid key (chosen from the current keys); whenMdrops, the group genuinely supports fewer subclusters, sosmoothed-kshould follow it down.Test plan
stale-subgroup-smoothed-k-is-clamped-to-available-subgroup-clustersinconv_edge_cases_test.clj, mirroring the existing group-levelstale-smoothed-k-is-clamped-to-available-group-clusters. Verified RED before the fix (smoothed-k=5 not in (2 3), downstream lookup → nil), GREEN after.🤖 Generated with Claude Code