Context
sq.gr.calculate_niche(flavor="cellcharter", ...) fits a GMM with a fixed, user-supplied n_components. CellCharter's own ClusterAutoK instead searches a range of K, refits the model max_runs times per K, scores stability via Fowlkes-Mallows similarity between labelings at K/K-1/K+1, and picks the K with highest stability (best_k, plus a peaks attribute for runner-up candidates). Squidpy's _get_GMM_clusters currently skips this -- its own docstring notes it's "simplified... without stability analysis."
Proposal
Port ClusterAutoK-style automatic K selection, with an input signature that mirrors CellCharter's own API rather than a magic-string trigger -- i.e. take a n_clusters range plus the same knobs CellCharter exposes (max_runs, convergence_tol, similarity_function, model_params), so behavior and defaults line up with the original.
Open question: integrate this as an option inside calculate_niche vs. a separate standalone function (e.g. sq.gr.cluster_auto_k) that returns best_k/stability curve/peaks, to be fed into calculate_niche afterward. Leaning toward separate/composable, since it's a stochastic multi-run search (many GMM refits across a K range) rather than a single deterministic fit, and bolting it into calculate_niche's already-branchy per-flavor validation adds complexity. Not settled yet -- needs discussion.
Dependency
Blocked on / should follow #1192 (refactor of calculate_niche into separate functions) -- final placement of auto-K selection depends on how that refactor shakes out.
cc: @sarajimenez
Context
sq.gr.calculate_niche(flavor="cellcharter", ...)fits a GMM with a fixed, user-suppliedn_components. CellCharter's ownClusterAutoKinstead searches a range of K, refits the modelmax_runstimes per K, scores stability via Fowlkes-Mallows similarity between labelings at K/K-1/K+1, and picks the K with highest stability (best_k, plus apeaksattribute for runner-up candidates). Squidpy's_get_GMM_clusterscurrently skips this -- its own docstring notes it's "simplified... without stability analysis."Proposal
Port
ClusterAutoK-style automatic K selection, with an input signature that mirrors CellCharter's own API rather than a magic-string trigger -- i.e. take an_clustersrange plus the same knobs CellCharter exposes (max_runs,convergence_tol,similarity_function,model_params), so behavior and defaults line up with the original.Open question: integrate this as an option inside
calculate_nichevs. a separate standalone function (e.g.sq.gr.cluster_auto_k) that returnsbest_k/stability curve/peaks, to be fed intocalculate_nicheafterward. Leaning toward separate/composable, since it's a stochastic multi-run search (many GMM refits across a K range) rather than a single deterministic fit, and bolting it intocalculate_niche's already-branchy per-flavor validation adds complexity. Not settled yet -- needs discussion.Dependency
Blocked on / should follow #1192 (refactor of
calculate_nicheinto separate functions) -- final placement of auto-K selection depends on how that refactor shakes out.cc: @sarajimenez