diff --git a/hidimstat/adaptive_permutation_threshold.py b/hidimstat/adaptive_permutation_threshold.py index 66e525d..d6dabe5 100644 --- a/hidimstat/adaptive_permutation_threshold.py +++ b/hidimstat/adaptive_permutation_threshold.py @@ -49,23 +49,24 @@ def ada_svr(X, y, rcond=1e-3): return beta_hat, scale -def _manual_inversion(X, rcond=1e-3, full_rank=False): - "Inverting taking care of low eigenvalues to increase numerical stability" +def _manual_inversion(X, rcond=1e-3): + """ + Inverting taking care of low eigenvalues to increase numerical stability + + Parameters + ----------- + X : ndarray, shape (n_features, n_features) + Data. + Base on usage of X in the main function, X is squared matrix and not full_ranked (for details see PR#58) + + """ X = np.asarray(X) - n_samples, n_features = X.shape - - if n_samples != n_features: - raise ValueError("The matrix is not a square matrix") - U, s, V = np.linalg.svd(X, full_matrices=False) rank = np.sum(s > rcond * s.max()) s_inv = np.zeros(np.size(s)) s_inv[:rank] = 1 / s[:rank] - if full_rank: - s_inv[rank:] = 1 / (rcond * s.max()) - X_inv = np.linalg.multi_dot([U, np.diag(s_inv), V]) return X_inv