Variance Explained Ratio
Compute the explained variance ratio from eigenvalues.
Given a list of eigenvalues (sorted descending), compute:
Also compute the cumulative explained variance ratio: entry is the running sum of the already rounded ratios up to and including , rounded again to 4 decimal places.
Return a tuple (ratios, cumulative) where both are lists rounded to 4 decimal places.
Example
eigenvalues = [4.0, 2.0, 1.0, 0.5]
([0.5333, 0.2667, 0.1333, 0.0667], [0.5333, 0.8, 0.9333, 1.0])
eigenvaluesholds , the variance captured along each principal direction. Here the total variance is .- Each ratio is one component's share of that total, rounded to 4 decimal places: , , , .
- Cumulative entry is the share explained by the first components together: , then , , .
- Both lists have one entry per eigenvalue. The ratios shrink because the eigenvalues are sorted descending, and the cumulative list climbs to because all components together explain all the variance.
- Notice the running total adds the already rounded ratios. With three equal eigenvalues each ratio is , so the last cumulative value is , not .
- Reading the result: the first two components already explain of the variance, so keeping 2 of 4 loses only .
Constraints
- eigenvalues: list of non-negative floats (sorted descending)
- Return (ratios, cumulative) rounded to 4 decimal places
- cumulative[i] = sum(ratios[0:i+1])