From 094955d32fa3b715b71aba59c3c8272e6b28a024 Mon Sep 17 00:00:00 2001 From: kusch lionel Date: Fri, 13 Dec 2024 16:37:59 +0100 Subject: [PATCH 1/4] Remove unnecessary functions --- hidimstat/adaptive_permutation_threshold.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hidimstat/adaptive_permutation_threshold.py b/hidimstat/adaptive_permutation_threshold.py index 66e525d..ae40f7b 100644 --- a/hidimstat/adaptive_permutation_threshold.py +++ b/hidimstat/adaptive_permutation_threshold.py @@ -49,7 +49,7 @@ def ada_svr(X, y, rcond=1e-3): return beta_hat, scale -def _manual_inversion(X, rcond=1e-3, full_rank=False): +def _manual_inversion(X, rcond=1e-3): "Inverting taking care of low eigenvalues to increase numerical stability" X = np.asarray(X) @@ -63,9 +63,6 @@ def _manual_inversion(X, rcond=1e-3, full_rank=False): 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 From b006a0858531fb677474c62bb35dd8d9f3fde79f Mon Sep 17 00:00:00 2001 From: lionel kusch Date: Fri, 13 Dec 2024 16:55:19 +0100 Subject: [PATCH 2/4] Update adaptive_permutation_threshold.py Remove the error because it's not possible to access it due to the operation of np.dot(X, X.T) on line 39. The only line using this function. --- hidimstat/adaptive_permutation_threshold.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/hidimstat/adaptive_permutation_threshold.py b/hidimstat/adaptive_permutation_threshold.py index ae40f7b..583e8a1 100644 --- a/hidimstat/adaptive_permutation_threshold.py +++ b/hidimstat/adaptive_permutation_threshold.py @@ -55,9 +55,6 @@ def _manual_inversion(X, rcond=1e-3): 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)) From 23f7f643e7c12f5c8936ed7d683f8ce57a7ad29e Mon Sep 17 00:00:00 2001 From: lionel kusch Date: Fri, 13 Dec 2024 16:58:21 +0100 Subject: [PATCH 3/4] Update adaptive_permutation_threshold.py variable unnecessary and without meaning in this context --- hidimstat/adaptive_permutation_threshold.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/hidimstat/adaptive_permutation_threshold.py b/hidimstat/adaptive_permutation_threshold.py index 583e8a1..1dc449a 100644 --- a/hidimstat/adaptive_permutation_threshold.py +++ b/hidimstat/adaptive_permutation_threshold.py @@ -53,8 +53,6 @@ def _manual_inversion(X, rcond=1e-3): "Inverting taking care of low eigenvalues to increase numerical stability" X = np.asarray(X) - n_samples, n_features = X.shape - U, s, V = np.linalg.svd(X, full_matrices=False) rank = np.sum(s > rcond * s.max()) s_inv = np.zeros(np.size(s)) From 3a920eaa72aabf03562de5fc668d324a01f55d93 Mon Sep 17 00:00:00 2001 From: lionel kusch Date: Mon, 16 Dec 2024 10:13:42 +0100 Subject: [PATCH 4/4] Update adaptive_permutation_threshold.py Add comment about the condition of X from the removal lines --- hidimstat/adaptive_permutation_threshold.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hidimstat/adaptive_permutation_threshold.py b/hidimstat/adaptive_permutation_threshold.py index 1dc449a..d6dabe5 100644 --- a/hidimstat/adaptive_permutation_threshold.py +++ b/hidimstat/adaptive_permutation_threshold.py @@ -50,7 +50,16 @@ def ada_svr(X, y, rcond=1e-3): def _manual_inversion(X, rcond=1e-3): - "Inverting taking care of low eigenvalues to increase numerical stability" + """ + 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) U, s, V = np.linalg.svd(X, full_matrices=False)