Skip to content

correct information imbalance normalization - #94

Merged
SpatLyu merged 5 commits into
stscl:mainfrom
SpatLyu:dev
Aug 17, 2026
Merged

correct information imbalance normalization#94
SpatLyu merged 5 commits into
stscl:mainfrom
SpatLyu:dev

Conversation

@SpatLyu

@SpatLyu SpatLyu commented Aug 17, 2026

Copy link
Copy Markdown
Member

This PR corrects a critical normalization error in the Information Imbalance calculation pipeline. The previous implementation used Npred as the normalization denominator, which caused II values to exceed the theoretical upper bound of 1 whenever Nlib > Npred. The corrected implementation uses Nlib (the library size) as the normalization base, ensuring that II values are strictly bounded within $[0, 1]$.

Background

Information Imbalance measures how well the neighborhood structure in space A (e.g., X) predicts the neighborhood structure in space B (e.g., Y):

$$\Delta(A \to B) = \frac{2}{N} \cdot \overline{r^B}$$

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:

return 2.0 / static_cast<double>(Npred) * mean_rank;

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} &gt; N_{pred}$ (common in cross-validation or out-of-sample settings), the computed II value becomes:

$$\Delta_{incorrect} = \frac{N_{lib}}{N_{pred}} > 1$$

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:

$$\Delta(X \to Y) = \frac{2}{N_{lib} \cdot N_{pred} \cdot k} \sum_{i=1}^{N_{pred}} \sum_{j \in \text{NN}_k^X(i)} r^Y_{ij}$$

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:

$$\Delta = \frac{2}{N_{lib}} \times \overline{r^B}$$

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:

Scenario Expected Conditional Rank II Value
Perfect prediction (k=1) 1 $2/N_{lib} \to 0$
Complete independence $N_{lib}/2$ $2/N_{lib} \cdot N_{lib}/2 = 1$
Partial association between $(0, 1)$

@SpatLyu SpatLyu self-assigned this Aug 17, 2026
@SpatLyu
SpatLyu merged commit 2bd128d into stscl:main Aug 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant