Make clustering competitive: unify engine, add scaling and target-K#13
Merged
Conversation
scale= (none/zscore/robust/arcsinh) learned at fit, reapplied at predict. affinityParams$alpha="auto" sets RBF/Laplace bandwidth by the median heuristic. epsilonQuantile= adapts suppression to the antibody spread. Result gains antibodies_unscaled; predict() now reads result$antibodies so test labels match training. Matured antibodies seed a Lloyd refinement coerced to K: agglomerate when the network kept >K prototypes, k-means++ split when <K. Decouples the reported count from emergent suppression.
Add coverageBoost and honeycomb smallClusterAction coverageBoost seeds antibodies at the worst-covered points after maturation. honeycombHIVE smallClusterAction (merge/keep/drop) stops small clusters being silently deleted; default merges into nearest.
Route bHIVE/swarm/honeycomb through the AINet engine bHIVE() is now a thin wrapper over AINet, so swarmbHIVE and honeycombHIVE inherit the C++ backends, consolidation, scaling, targetK and modules. Legacy pure-R loop removed. swarmbHIVE forwards all grid columns. Tests updated for t
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.
Benchmarking for the manuscript showed bHIVE trailing on cytometry and single-cell data. It could not control the final cluster count and missed prominent cell populations. The matched-k analysis pinned the cause: about 80% of the ARI gap was the cluster-count heuristic, not prototype placement. This PR targets that directly and folds in the supporting fixes.
What changed
Unified engine.
bHIVE()is now a thin wrapper over theAINetR6 engine.swarmbHIVE()andhoneycombHIVE()callbHIVE(), so they inherit the C++ clonal-selection and suppression backends, Lloyd consolidation, scaling, target-K, and all composable immunology modules. The old pure-R loop is removed.swarmbHIVE()now forwards every grid column tobHIVE(), so any argument is tunable, not just nAntibodies/beta/epsilon.Input scaling. New
scaleargument (none/zscore/robust/arcsinh), learned at fit and reapplied at predict. epsilon, mutation scale, and distances live in feature units, so scaling makes the same defaults behave consistently across datasets.affinityParams$alpha = "auto"sets the RBF bandwidth by the median heuristic, which matters in high dimensions where the fixed alpha=1 saturates the kernel.Target-K clustering. New
targetKargument forces exactly K clusters. Affinity maturation still finds where prototypes belong, then a seeded K-means refinement coerces the count: agglomerate when the network kept more than K, k-means++ split when fewer.Rare-population protection. New
coverageBoostseeds antibodies at the worst-covered points after maturation.honeycombHIVE()gainssmallClusterAction(merge/keep/drop). Small clusters are now merged into the nearest prototype or kept, instead of being silently deleted.Also adds
epsilonQuantilefor scale-free suppression and returnsantibodies_unscaledfor interpretation in original units.Validation
Real Levine CyTOF, ARI on labeled cells:
The new path fixes the cluster count, raises ARI 2.9x, and beats stock k-means on the same transformed data.
Compatibility
The historical return fields (antibodies, assignments, task) are unchanged. The return list gains
antibodies_unscaledand, frombHIVE(), amodelhandle. Cosine affinity paired with a non-cosine distance now warns via the metric guard. Tests updated accordingly. All 643 tests pass.Version bumped to 0.99.6.