cdt15 / lingam

Python package for causal discovery based on LiNGAM.
https://sites.google.com/view/sshimizu06/lingam
MIT License
356 stars 54 forks source link

Test Error: ValueError: 'x0' must only have one dimension. #93

Closed ikeuchi-screen closed 12 months ago

ikeuchi-screen commented 1 year ago

I get the following error when I run the lina.py test.

FAILED tests/test_lina.py::test_fit_lina - ValueError: 'x0' must only have one dimension.
FAILED tests/test_lina.py::test_fit_mdlina - ValueError: 'x0' must only have one dimension.

The following changes in scipy-1.11.0 may have affected this.

SciPy 1.11.0 Release Notes

ikeuchi-screen commented 1 year ago

factor_analyzer used in lina.py is using scipy.minimize.

lingam/lina.py:316: in fit
    cfa.fit(X, G_sign)
/usr/local/lib/python3.10/site-packages/factor_analyzer/confirmatory_factor_analyzer.py:742: in fit
    res = minimize(
ikeuchi-screen commented 1 year ago

@YanaZeng I don't understand the LiNA algorithm very well. As mentioned above, it may be a problem with the factor_analyzer library. Do you know how we can solve this problem?

YanaZeng commented 1 year ago

Ikeuchi-san, I try to run the code, but without this error. Maybe it's due to the versions of scipy or factor_analyzer.

I used factor_analyzer 0.4.1 and scipy 1.9.3. And my 'x0' here is a 1d vector. Could you print your 'x0'?

ikeuchi-screen commented 1 year ago

Hi, @YanaZeng Thank you for your confirmation! I believe this is caused by a change in scipy-1.11.0, as mentioned in my opening post. (factor_analyzer-0.4.1, scipy-1.11.0)

The test code execution resulted in the following x0 values. This shape is a 2d-array.

x0 = array([[1.  ],
       [1.  ],
       [0.  ],
       [0.  ],
       [0.  ],
       [0.  ],
       [0.  ],
       [0.  ]...      [0.05],
       [0.05],
       [0.05],
       [0.05],
       [0.05],
       [0.05],
       [0.05],
       [0.05]])

The results of the test code execution can be found at the following link: https://github.com/cdt15/lingam/actions/runs/5376105848/jobs/9752810059#step:6:155

ikeuchi-screen commented 1 year ago

@YanaZeng I have made a pull request to factor_analyzer GitHub on how to fix this problem. https://github.com/EducationalTestingService/factor_analyzer/pull/124

However, I don't think it will be merged for a while, so I will fix it so that the LiNA test will not run.

YanaZeng commented 1 year ago

Get it, Ikeuchi-san! お疲れ様でした.

ikeuchi-screen commented 12 months ago

I close this issue because the PullRequest for factor_analyzer has been merged. https://github.com/EducationalTestingService/factor_analyzer/pull/124