-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Desparsified lasso(1/4): add comments and docstring of the functions #127
Open
lionelkusch
wants to merge
47
commits into
mind-inria:main
Choose a base branch
from
lionelkusch:PR_desparsified_lasso
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
99fa174
Remove the method parameter because only lasso is supported
lionelkusch 3eebe97
Comment reid procedure
lionelkusch ffbb6e9
update comment
lionelkusch f92ea4d
Comments desparsified and reorganise the structure
lionelkusch d465c36
Improve comment and let's 2 question?
lionelkusch eeae34b
Comment deparsified lasso grouping
lionelkusch d23e3d6
format
lionelkusch 4ad785c
comment group_red
lionelkusch 4787c27
Comment emperical snr
lionelkusch 97ff04f
Comment the side function of desparsified lasso
lionelkusch 4cdaf90
Fix bugs
lionelkusch 931e52f
Put back stationnary noise
lionelkusch d3d91e8
Fix the changement of signature
lionelkusch 92c7f57
Modify documentation to include new function
lionelkusch 8366e70
Add a question
lionelkusch e81e3db
Improve commit
lionelkusch 9052326
remove unecesary parameter
lionelkusch 7e4435a
Merge branch 'main' into PR_desparsified_lasso
lionelkusch 8068e89
Fix citation
lionelkusch b4055a3
Add reference to citation
lionelkusch 109dcd2
Improve docstring with copilot
lionelkusch 0ca0ec1
Add test
lionelkusch 977cd30
Improve docstring
lionelkusch f25cc8c
Format files
lionelkusch f304a5e
Format files
lionelkusch aa44640
Remove memory parameters
lionelkusch ab0ebd5
Update the function
lionelkusch 9081811
Group the function in one
lionelkusch e2dd939
Update the tests
lionelkusch aea49d6
Fix usage of the function
lionelkusch 4b376c7
Remove one option for confidence interval
lionelkusch 6c9989a
Formating
lionelkusch 0511cc6
Formating files
lionelkusch 942a508
update reference
lionelkusch 6001f9b
Fix bugs
lionelkusch ef5ec38
formating
lionelkusch c5a070f
Merge branch 'main' into PR_desparsified_lasso
lionelkusch 9a099b9
Improve coverage
lionelkusch e9ba724
Improve coverage
lionelkusch 44985a1
Apply suggestions from code review
lionelkusch 367d0df
Update the doctsring of a file
lionelkusch 0d09b9b
Apply suggestions from code review
lionelkusch 7c6ada3
Replace lambda by alpha
lionelkusch 9dbebc4
Merge branch 'PR_desparsified_lasso' of https://github.com/lionelkusc…
lionelkusch 91c8b67
Replace distrib by distribution
lionelkusch 1b381a5
format
lionelkusch f9f6f0f
Add dimension of array in docstring
lionelkusch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import numpy as np | ||
from sklearn.preprocessing import StandardScaler | ||
from sklearn.utils import resample | ||
from sklearn.utils.validation import check_memory | ||
|
||
from .desparsified_lasso import desparsified_group_lasso, desparsified_lasso | ||
from .stat_tools import pval_from_cb | ||
from .desparsified_lasso import ( | ||
desparsified_lasso, | ||
desparsified_lasso_pvalue, | ||
desparsified_group_lasso_pvalue, | ||
) | ||
|
||
|
||
def _subsampling(n_samples, train_size, groups=None, seed=0): | ||
|
@@ -45,7 +47,7 @@ def _ward_clustering(X_init, ward, train_index): | |
return X_reduced, ward | ||
|
||
|
||
def hd_inference(X, y, method, n_jobs=1, memory=None, verbose=0, **kwargs): | ||
def hd_inference(X, y, method, n_jobs=1, verbose=0, **kwargs): | ||
"""Wrap-up high-dimensional inference procedures | ||
|
||
Parameters | ||
|
@@ -65,11 +67,6 @@ def hd_inference(X, y, method, n_jobs=1, memory=None, verbose=0, **kwargs): | |
n_jobs : int or None, optional (default=1) | ||
Number of CPUs to use during parallel steps such as inference. | ||
|
||
memory : str or joblib.Memory object, optional (default=None) | ||
Used to cache the output of the computation of the clustering | ||
and the inference. By default, no caching is done. If a string is | ||
given, it is the path to the caching directory. | ||
|
||
verbose: int, optional (default=1) | ||
The verbosity level. If `verbose > 0`, we print a message before | ||
runing the clustered inference. | ||
|
@@ -96,34 +93,28 @@ def hd_inference(X, y, method, n_jobs=1, memory=None, verbose=0, **kwargs): | |
one_minus_pval_corr : ndarray, shape (n_features,) | ||
One minus the p-value corrected for multiple testing. | ||
""" | ||
|
||
if method == "desparsified-lasso": | ||
|
||
beta_hat, cb_min, cb_max = desparsified_lasso( | ||
X, | ||
y, | ||
confidence=0.95, | ||
n_jobs=n_jobs, | ||
memory=memory, | ||
verbose=verbose, | ||
**kwargs, | ||
) | ||
pval, pval_corr, one_minus_pval, one_minus_pval_corr = pval_from_cb( | ||
cb_min, cb_max, confidence=0.95 | ||
) | ||
|
||
elif method == "desparsified-group-lasso": | ||
|
||
beta_hat, pval, pval_corr, one_minus_pval, one_minus_pval_corr = ( | ||
desparsified_group_lasso( | ||
X, y, n_jobs=n_jobs, memory=memory, verbose=verbose, **kwargs | ||
if method not in ["desparsified-lasso", "desparsified-group-lasso"]: | ||
raise ValueError("Unknow method") | ||
group = method == "desparsified-group-lasso" | ||
print("hd_inference", group, kwargs) | ||
beta_hat, theta_hat, omega_diag = desparsified_lasso( | ||
X, y, group=group, n_jobs=n_jobs, verbose=verbose, **kwargs | ||
) | ||
if not group: | ||
pval, pval_corr, one_minus_pval, one_minus_pval_corr, cb_min, cb_max = ( | ||
desparsified_lasso_pvalue( | ||
X.shape[0], | ||
beta_hat, | ||
theta_hat, | ||
omega_diag, | ||
confidence=0.95, | ||
**kwargs, | ||
) | ||
) | ||
|
||
else: | ||
|
||
raise ValueError("Unknow method") | ||
|
||
pval, pval_corr, one_minus_pval, one_minus_pval_corr = ( | ||
desparsified_group_lasso_pvalue(beta_hat, theta_hat, omega_diag, **kwargs) | ||
) | ||
return beta_hat, pval, pval_corr, one_minus_pval, one_minus_pval_corr | ||
|
||
|
||
|
@@ -178,7 +169,6 @@ def clustered_inference( | |
method="desparsified-lasso", | ||
seed=0, | ||
n_jobs=1, | ||
memory=None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment: why get rid of memory ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above |
||
verbose=1, | ||
**kwargs, | ||
): | ||
|
@@ -220,11 +210,6 @@ def clustered_inference( | |
n_jobs : int or None, optional (default=1) | ||
Number of CPUs to use during parallel steps such as inference. | ||
|
||
memory : str or joblib.Memory object, optional (default=None) | ||
Used to cache the output of the computation of the clustering | ||
and the inference. By default, no caching is done. If a string is | ||
given, it is the path to the caching directory. | ||
|
||
verbose: int, optional (default=1) | ||
The verbosity level. If `verbose > 0`, we print a message before | ||
runing the clustered inference. | ||
|
@@ -257,9 +242,6 @@ def clustered_inference( | |
Spatially relaxed inference on high-dimensional linear models. | ||
arXiv preprint arXiv:2106.02590. | ||
""" | ||
|
||
memory = check_memory(memory) | ||
|
||
n_samples, n_features = X_init.shape | ||
|
||
if verbose > 0: | ||
|
@@ -273,20 +255,26 @@ def clustered_inference( | |
train_index = _subsampling(n_samples, train_size, groups=groups, seed=seed) | ||
|
||
# Clustering | ||
X, ward = memory.cache(_ward_clustering)(X_init, ward, train_index) | ||
X, ward = _ward_clustering(X_init, ward, train_index) | ||
|
||
# Preprocessing | ||
X = StandardScaler().fit_transform(X) | ||
y = y - np.mean(y) | ||
|
||
# Inference: computing reduced parameter vector and stats | ||
print("Clustered inference", kwargs) | ||
beta_hat_, pval_, pval_corr_, one_minus_pval_, one_minus_pval_corr_ = hd_inference( | ||
X, y, method, n_jobs=n_jobs, memory=memory, **kwargs | ||
X, y, method, n_jobs=n_jobs, **kwargs | ||
) | ||
|
||
# De-grouping | ||
beta_hat, pval, pval_corr, one_minus_pval, one_minus_pval_corr = _degrouping( | ||
ward, beta_hat_, pval_, pval_corr_, one_minus_pval_, one_minus_pval_corr_ | ||
ward, | ||
beta_hat_, | ||
pval_, | ||
pval_corr_, | ||
one_minus_pval_, | ||
one_minus_pval_corr_, | ||
) | ||
|
||
return beta_hat, pval, pval_corr, one_minus_pval, one_minus_pval_corr |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you remove the memory argument ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This argument is for optimisation of the calculation by memorising the results of a call of a function with the same arguments. I don't think the basic user requires it and I don't take the time to look in detail if it's very efficient.
I think that it's interesting when the function is run multiple times on the same data but I don't think that it's important to keep it for the moment because it should be the case.