correct information imbalance normalization - #94
Merged
Conversation
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.
This PR corrects a critical normalization error in the Information Imbalance calculation pipeline. The previous implementation used$[0, 1]$ .
Npredas the normalization denominator, which caused II values to exceed the theoretical upper bound of 1 wheneverNlib > Npred. The corrected implementation usesNlib(the library size) as the normalization base, ensuring that II values are strictly bounded withinBackground
Information Imbalance measures how well the neighborhood structure in space A (e.g., X) predicts the neighborhood structure in space B (e.g., Y):
Under the null hypothesis of independence between A and B, ranks follow a uniform distribution with expected value$N/2$ , yielding $\Delta = 1$ . When A perfectly predicts B, ranks concentrate near 1, yielding $\Delta \to 0$ .
Problem
The previous implementation used:
Since ranks are computed within the library space (size$N_{lib}$ ), the expected rank under independence is $N_{lib}/2$ , not $N_{pred}/2$ . When $N_{lib} > N_{pred}$ (common in cross-validation or out-of-sample settings), the computed II value becomes:
This violates the theoretical bound$\Delta \in [0, 1]$ and renders downstream metrics (e.g., Information Imbalance Gain) meaningless.
Mathematical Verification
For the corrected formula, the Information Imbalance is computed as:
where$NN_k^X(i)$ denotes the set of $k$ nearest neighbours of prediction point $i$ in the X space, and $r^Y_{ij}$ is the rank of library point $j$ in the Y space with respect to point $i$ . Only the ranks corresponding to the selected $k$ nearest neighbours in X are included in the summation.
This is algebraically equivalent to:
where$\overline{r^B} = \frac{1}{N_{pred}} \sum_{i=1}^{N_{pred}} \left( \frac{1}{k} \sum_{j \in NN_k^X(i)} r^Y_{ij} \right)$ is the mean conditional rank across all prediction points.
For the corrected formula: