py-why / py-why/causal-learn

array must not contain infs or NaNs

Open
#182 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.7k
Forks
274
PR merge metrics
No merged PRs in 30d

Description

Hi, when I try to run this code, there is an error:

from causallearn.search.FCMBased import lingam
model = lingam.ICALiNGAM()
model.fit(data)

from causallearn.search.FCMBased.lingam.utils import make_dot
make_dot(model.adjacency_matrix_, labels=labels)

error:

C:\Users\.conda\envs\causalenv\Lib\site-packages\sklearn\decomposition\_fastica.py:626: RuntimeWarning: invalid value encountered in divide
  K = (u / d).T[:n_components]  # see (6.33) p.140
Traceback (most recent call last):
  File "f:\causal.py", line 81, in <module>
    model.fit(data)
  File "C:\Users\.conda\envs\causalenv\Lib\site-packages\causallearn\search\FCMBased\lingam\ica_lingam.py", line 55, in fit
    ica.fit(X)
  File "C:\Users\.conda\envs\causalenv\Lib\site-packages\sklearn\base.py", line 1474, in wrapper
    return fit_method(estimator, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\.conda\envs\causalenv\Lib\site-packages\sklearn\decomposition\_fastica.py", line 733, in fit
    self._fit_transform(X, compute_sources=False)
  File "C:\Users\.conda\envs\causalenv\Lib\site-packages\sklearn\decomposition\_fastica.py", line 660, in _fit_transform
    W, n_iter = _ica_par(X1, **kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\.conda\envs\causalenv\Lib\site-packages\sklearn\decomposition\_fastica.py", line 118, in _ica_par
    W1 = _sym_decorrelation(np.dot(gwtx, X.T) / p_ - g_wtx[:, np.newaxis] * W)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\.conda\envs\causalenv\Lib\site-packages\sklearn\decomposition\_fastica.py", line 61, in _sym_decorrelation
    s, u = linalg.eigh(np.dot(W, W.T))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\.conda\envs\causalenv\Lib\site-packages\scipy\linalg\_decomp.py", line 460, in eigh
    a1 = _asarray_validated(a, check_finite=check_finite)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\.conda\envs\causalenv\Lib\site-packages\scipy\_lib\_util.py", line 240, in _asarray_validated
    a = toarray(a)
        ^^^^^^^^^^
  File "C:\Users\.conda\envs\causalenv\Lib\site-packages\numpy\lib\function_base.py", line 630, in asarray_chkfinite
    raise ValueError(
ValueError: array must not contain infs or NaNs

I used my own dataset, and checked there was no infs and NaNs, can you help me to fix it up?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at causallearn/search/FCMBased/lingam/ica_lingam.py where model.fit(data) calls sklearn's FastICA, then compare the reported dataset with the validation and numerical warnings in the traceback. Reproduce the failure if the dataset is available and determine whether the library should handle the resulting invalid values; done means the cause is documented or covered by a regression test and the fitting behavior is defined.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, scikit-learn
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.