Skip to content

Add RMS Davies-Bouldin and the q=2 family with configurable centroid distance #141

Open

Description

@NiklasMelton

Motivation

Follow-up to #137. Exact scikit-learn DB (q=1, mean Euclidean scatter) cannot meet CVI's compact-state incremental requirement for unrestricted inputs. The original Davies-Bouldin q=2 family can: its RMS scatter is recoverable from the sufficient statistics CVI already maintains.

Implement RMS DB and the wider q=2 family in one new class. RMS DB with Euclidean centroid separation is simply the p=2 default of that family, so separate classes or implementation issues are unnecessary.

Definition and public API

For cluster count $K$, membership count $n_i$, arithmetic centroid $\mu_i$, and squared Euclidean compactness $CP_i$:

$$ CP_i = \sum_{x\in C_i}|x-\mu_i|_2^2,\qquad S_i = \sqrt{CP_i/n_i},\qquad M_{ij}=|\mu_i-\mu_j|_p, $$

$$ DB_{p,2}=\frac{1}{K}\sum_i\max_{j\ne i}\frac{S_i+S_j}{M_{ij}}. $$

  • Add a clearly named public class, e.g. DBRMS(p=2, backend="numpy"), with factory registration and capability metadata. Final naming should identify the RMS scatter unambiguously.
  • Fix q=2. Expose and validate finite real p >= 1; explicitly document whether the optional p=inf limit is supported. Cover Manhattan (p=1), Euclidean (p=2), and a noninteger p in tests.
  • p changes only the between-centroid Minkowski norm. Within-cluster scatter always remains Euclidean RMS, computed from CP_i. Using squared Lp residuals within clusters for arbitrary p would define a different metric and invalidate reuse of the current compactness recurrence.
  • Preserve existing DB results, defaults, and public behavior. Its mean-squared scatter / squared separation definition remains a distinct published relative.
  • Do not expose unsupported q=1 updates or describe the new class as numerically equivalent to scikit-learn DB.

Implementation scope

  • Reuse the existing count, centroid, squared-compactness, and numerical residual state and the batch/incremental update formulas. Apply the RMS transformation only when deriving scatter for scoring.
  • Retain no historical observations. State size should remain dependent on cluster count and feature dimension, not accumulated samples: O(K*d + K^2) for the current dense pairwise layout.
  • Support initial batch evaluation, incremental initialization, and a batch followed by sample additions, under the existing get_cvi contract. Repeated batch updates are not part of this issue.
  • Support removal, merging, and splitting through the existing compactness-based operations. Split input compactness remains the subset's sum of squared Euclidean deviations, not RMS scatter.
  • Update the affected centroid-distance row/column on additions and rebuild distances consistently after structural operations. Reuse Euclidean backend kernels for p=2 where appropriate and implement the other supported norms without changing existing indices' defaults.
  • Provide NumPy support. Clearly declare any additional backend support; do not advertise unsupported p/backend combinations. JAX expansion is not required by this issue.
  • Specify undefined-state behavior consistently with CVI, including fewer than two clusters, coincident centroids, singleton clusters, and zero scatter. Scikit-learn-specific degeneracy shortcuts are not an equivalence target.

Validation and documentation

  • Compare the result with an independent direct sample-based oracle for the stated formula, for every supported p category. The oracle may retain samples in tests; the implementation must not.
  • Verify batch versus full-stream versus batch-then-stream equivalence within appropriate floating-point tolerances, including new/nonconsecutive labels.
  • Verify remove, merge, and summary-based split results against fresh evaluation of the corresponding partition, and verify subsequent additions still agree.
  • Include targeted degenerate and numerical cases, invalid p values, and regression coverage preserving existing squared DB behavior.
  • Document the original p=q=2 definition, configurable centroid separation, operation/backend support, storage and update costs, and the distinction from both current DB and scikit-learn's q=1 score.
  • Label any benchmark comparisons by definition; scikit-learn DB must not be presented as an equivalent oracle or equivalent implementation for this class. A broad benchmark campaign is not required here.

Done when

A single public q=2 DB class provides RMS DB at its p=2 default and the documented centroid Minkowski family, with exact mathematical batch/incremental/structural equivalence up to floating-point error, without retaining observations or changing existing DB behavior.

References

Activity

  1. added
    enhancement
    on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions