Skip to content

FastICA G function #13104

Closed
Closed

Description

@Mahdi-Hosseinali

sklearn.decomposition.FastICA throws broadcast error when g function aregument is present

import numpy as np
from sklearn.decomposition import FastICA

t=np.linspace(0,2*np.pi)
S=np.c_[np.sin(t),np.cos(2*t)]
def my_g(x):
    return x**3,3*x**2  # from documents
ica=FastICA(fun=my_g)
ica.fit(S)

Which throws:

Traceback (most recent call last):

File "", line 1, in
ica.fit(S.T)

File "C:\Users\mhossein\Anaconda3\lib\site-packages\sklearn\decomposition\fastica_.py", line 535, in fit
self._fit(X, compute_sources=False)

File "C:\Users\mhossein\Anaconda3\lib\site-packages\sklearn\decomposition\fastica_.py", line 487, in _fit
compute_sources=compute_sources, return_n_iter=True)

File "C:\Users\mhossein\Anaconda3\lib\site-packages\sklearn\decomposition\fastica_.py", line 340, in fastica
W, n_iter = _ica_par(X1, **kwargs)

File "C:\Users\mhossein\Anaconda3\lib\site-packages\sklearn\decomposition\fastica_.py", line 110, in _ica_par
- g_wtx[:, np.newaxis] * W)

ValueError: operands could not be broadcast together with shapes (2,1,50) (2,2)

Versions

Windows-7-6.1.7601-SP1
NumPy 1.13.3
SciPy 1.1.0
Scikit-Learn 0.19.1

Activity

  1. adrinjalali commented on Feb 6, 2019

    @adrinjalali
    Member

    Seems like a documentation error, the tests have it as:

    def my_g(x):
        return x ** 3, (3 * x ** 2).mean(axis=-1) 
  2. added
    Easy
    on Feb 6, 2019
  3. Mahdi-Hosseinali commented on Feb 6, 2019

    @Mahdi-Hosseinali
    Author

    That's right, it works when I add the mean.

  4. algo-circle commented on Feb 7, 2019

    @algo-circle
    Contributor

    @adrinjalali
    I was looking through the documentation and checked the sklearn/decomposition/fastica_.py file but couldn't figure out a way to fix this issue. Could you tell a little bit more about this issue and how to approach this one as I am new to Open Source contributions but nevertheless keen to contribute to the organization.

  5. JamesTrick commented on Feb 7, 2019

    @JamesTrick
    Contributor

    @algo-circle

    Start by searching the repo for the function my_g(x) and you should find the relevant piece of documentation here.

    For general contributing to open source, I found this guide pretty helpful just to understand the git workflow :).

  6. algo-circle commented on Feb 8, 2019

    @algo-circle
    Contributor

    @JamesTrick

    Thank you for the help. I'll be working on this issue now. Will soon make a pull request regarding the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationEasyhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions