-
Notifications
You must be signed in to change notification settings - Fork 84
proximal gradient method @ group lasso fixed #249
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bfdb111
proximal gradient method @ group lasso fixed
umegaki-msi f14aefe
test code for group lasso writed
AnchorBlues 0fb0606
test code for group lasso fixed
AnchorBlues b59e62d
removed assetion of last line because it is not appropriate.
AnchorBlues 66e9f13
pep8 fix
AnchorBlues 0d3c3ae
one of the groups must be [all zero]
AnchorBlues 5b9668e
one of the groups must be [all zero] fixed.
AnchorBlues 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -123,16 +123,33 @@ def test_group_lasso(): | |
| beta[groups == 2] = 0. | ||
|
|
||
| # create an instance of the GLM class | ||
| glm_group = GLM(distr='softplus', alpha=1.) | ||
| glm_group = GLM(distr='softplus', alpha=1., reg_lambda=0.2, group=groups) | ||
|
|
||
| # simulate training data | ||
| np.random.seed(glm_group.random_state) | ||
| Xr = np.random.normal(0.0, 1.0, [n_samples, n_features]) | ||
| yr = simulate_glm(glm_group.distr, beta0, beta, Xr) | ||
|
|
||
| # scale and fit | ||
| scaler = StandardScaler().fit(Xr) | ||
| glm_group.fit(scaler.transform(Xr), yr) | ||
|
|
||
| # count number of nonzero coefs for each group. | ||
| # in each group, coef must be [all nonzero] or [all zero]. | ||
| beta = glm_group.beta_ | ||
| group_ids = np.unique(groups) | ||
| for group_id in group_ids: | ||
| if group_id == 0: | ||
| continue | ||
|
|
||
| target_beta = beta[groups == group_id] | ||
| n_nonzero = (target_beta != 0.0).sum() | ||
| assert n_nonzero in (len(target_beta), 0) | ||
|
|
||
| # one of the groups must be [all zero] | ||
| assert np.any([beta[groups == group_id].sum() == 0 \ | ||
|
Member
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. you don't need the trailing backslash here but I can live with it |
||
| for group_id in group_ids if group_id != 0]) | ||
|
|
||
|
|
||
| def test_glmnet(): | ||
| """Test glmnet.""" | ||
|
|
||
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.
I like the test as it's compact. But the problem is that it passes on
master. Ideally, you want the test to fail onmasterbranch so the bug does not happen againThere 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.
OK, I added the following assertion to the test code.
I made sure that this assertion assert False at
masterbranch, and assert True after fixed.