Implement mdn_with_collinearity(f, X, y, sigma_tilde_inv, N), the extended Metadata Normalization (MDN) that removes metadata effects from features while keeping label-related variance. Metadata and label are regressed jointly, and only the metadata component is subtracted.
Inputs: features f of shape (M,D), metadata X of shape (M,K), labels y of shape (M,) or (M,1), sigma_tilde_inv =Σ~−1 of shape (K+1,K+1) (given inverse covariance of the augmented design), and N, the number of training samples.
- Augmented design: X~=[Xy] of shape (M,K+1) (treat
y as a column).
- Cross-moment: E~=M1X~⊤f, shape (K+1,D).
- Joint coefficients: β~=NΣ~−1E~, shape (K+1,D).
- Metadata part only: βX = the first K rows of β~; the last row (the label's) is discarded.
- Residual: r=f−XβX.
Return r as a NumPy array of shape (M,D).