Repository navigation
Conversation
| if (n_components > min(n, p)): | ||
| n_components = min(n, p) | ||
| warnings.warn('n_components is too large: it will be set to %s' % n_components) | ||
| warnings.warn( |
There was a problem hiding this comment.
please revert formatting changes.
There was a problem hiding this comment.
I run pycodestyle to autoformat the code. Apparently, that line was changed by it. I couldn't found in the documentation of the stable version how to format the code. Is there an automatic way to do the formatting?
Got it. I'll revert the changes in the next PR.
There was a problem hiding this comment.
We follow PEP8. Some editors/IDEs give suggestions and warnings as you code, but the configurations depends on the editor you use, and not included in the contributing guides.
You can always run flake8 on your code to see if there are any issues.
| whiten : boolean, optional | ||
| If whiten is false, the data is already considered to be | ||
| whitened, and no whitening is performed. | ||
| whiten : string or boolean, optional. Default: 'unit-variance' |
There was a problem hiding this comment.
| whiten : string or boolean, optional. Default: 'unit-variance' | |
| whiten : string or boolean, optional (default='unit-variance') |
| ch_num = signal.shape[0] | ||
| signal = signal.transpose() | ||
| ica = FastICA(n_components=ch_num, whiten=True) | ||
| _ = ica.fit_transform(signal) |
There was a problem hiding this comment.
use a with pytest.warns(...) construct please.
| "and whiten=True will behave like whiten='unit-variance'.", | ||
| category=DeprecationWarning) | ||
| elif self.whiten == 'unit-variance': | ||
| self.whiten = True |
There was a problem hiding this comment.
use a local variable instead of changing the value of self.whiten
|
I'll take a look at the paper and see if there is something else wrong with the implementation, as @jnothman said about the rescaling of If you have any suggestions about the tests or the implementation, are really welcome. @adrinjalali in the next PR I'll also fix the format errors that you mentioned above. |
|
@fferrin you should just push more commits to the same branch, you don't need to open a new PR. |
| if whiten: | ||
| if compute_sources: | ||
| S = np.dot(np.dot(W, K), X).T | ||
| S /= np.sqrt(np.var(S)) |
There was a problem hiding this comment.
S should have shape (n_samples, n_components) here. np.var(S) will compute the variance over all sources (components) and samples rather than for each source across samples.
| S /= np.sqrt(np.var(S)) | |
| S_std = np.std(S, axis=0, keepdims=True) | |
| S /= S_std |
Then, to make this equation consistent again
S = np.dot(np.dot(W, K), X).Tyou'll need to modify the right side by modifying W
W /= S_std.T|
This is looking pretty good? Any reason to continue marking it as WIP? Please add an entry to the change log at |
| # else: | ||
| # S = None | ||
|
|
||
| S = np.dot(np.dot(W, K), X).T |
There was a problem hiding this comment.
there's no need to compute S if compute_sources is False, this would be unnecessary computation.
There was a problem hiding this comment.
I know, but if I don't do that, the value of W is wrong (by a factor of 10 in the test). I couldn't find a way to update W without computing S. Any ideas?
There was a problem hiding this comment.
Fair point! I guess in that case it's also fair to update the description of compute_sources parameter, maybe.
There was a problem hiding this comment.
Great! If that's okay, I'll delete the commented lines (from 355 to 361).
Regarding the parameter compute_sources would it be something like this?
compute_sources: bool, optional
Sources are computed in any case because they are needed to compute the
estimated un-mixing matrix. If False, sources are not returned (default=True).
| def __init__(self, n_components=None, algorithm='parallel', whiten=True, | ||
| fun='logcosh', fun_args=None, max_iter=200, tol=1e-4, | ||
| w_init=None, random_state=None): | ||
|
|
There was a problem hiding this comment.
please revert this formatting change.
There was a problem hiding this comment.
Yes, sorry about the formatting. I'll revert all the formatting changes made by pycodestyle
| fun_args = {} if self.fun_args is None else self.fun_args | ||
|
|
||
| whiten = self.whiten | ||
| if whiten is True: |
There was a problem hiding this comment.
I guess this validation could be done in fastica() and not here. That function also needs to understand unit-variance if we're changing the default here. And any module using that function should get the same warning I suppose.
There was a problem hiding this comment.
I followed the guide from here (the fourth paragraph), and makes sense to me because unit-variance and True are they behave in the same way for fastica(). Of course, I only know about one or two modules of the project, so if you say so I'll change it, but I wanted to point that out.
Also, fastica() is only used by the tests and by FastICA class. Would it then make sense then to change fastica() to a private function?
|
I have a few questions / doubts:
|
|
This doesn't look like it is maintaining backwards compatible behaviour for whiten=True. I don't really get why we now need to compute sources when all we are changing is a scaling factor being the shape of X |
|
I think you will get the same results using either At first, I changed the scaling factor for |
|
Backwards compatibility means that whiten=True gets the same results before
and after this PR
|
|
Is it possible to change the scaling of W without S when
compute_sources=False?
|
|
I think the backward compatibility is maintained because when Regarding |
|
Sorry the reviews here have been slow. This PR modifies doc/whats_new/v0.21.rst, but this patch won't be released in version 0.21. This changelog entry should be moved to doc/whats_new/v0.22.rst after merging master. You can use something like: Sorry that this didn't make it into 0.21. We will work towards another release before the end of the year. |
|
Can you please resolve the conflicts and update this changelog as @jnothman suggested? |
Yes! Sorry about the delay! I'll fix the conflicts before tomorrow. |
Perhaps. Or perhaps we shouldn't raise the warning if, for that dataset, the result with unit variance will be the same as the result with whiten=True. We've done similar for scaling in SVMs I think. |
|
Maybe is a good idea to warn the user anyway because he/she could think that FastICA with I'll check SVM to see what it's doing anyway but I'd like to know if what I said makes sense to you. |
The point is to warn them that the behaviour for that particular invocation (without specifying |
|
Do you mind implementing that change, @fferrin, which will only raise the warning where the behaviour would change in the future? |
|
Sorry @jnothman for making this fix longer than expected but I make one last consultation to make sure that I did not misunderstand you. As I see there are 3 different situations, and I have doubt what to return and what warnings to raise in each one.
|
|
How about:
|
|
Two more questions:
|
I'm suggesting that we create it in this PR.
Indeed, we'd have |
|
Hi @fferrin, thanks for your work! Are you still interested in working on this pull request? If so, do you mind fixing conflicts? |
|
Hi @cmarmo ! Sorry for the delay. I'm a little bit busy now, so I'm not sure I'll be able to finish this right now, but I'd be glad to do this before the next release |
|
We'd also be able to find someone to help complete the work, @fferrin. I suppose the concern is that if we try to close this release milestone over the next 6 weeks, we need the contribution to get two approvals (perhaps from volunteer developers) in that time. |
|
@jnothman I'll be a bit busy this week but I'll try to continue with this work. Sorry about the delay. In case someone continue with this work, I can help, no problem with that 🙂 |
|
Hi @fferrin, Are you interested in pursuing your PR? 🙂 |
|
I'd love to but not sure if I'll be able to do it. I'd invite someone else to continue with this, but I'll try to continue working on this during weekends |

Reference Issues/PRs
Fixes #13056
What does this implement/fix? Explain your changes.
There was an error in the implementation of the FastICA algorithm since, when the
whitenparameter was set toTrue, the variance of the result was not1.0. In this PR, this is corrected and also the default valueTrueof thewhitenparameter is changed to'unit-variance'.Any other comments?