Skip to content
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

cost.LeastSquares fails with data with more than 2 dimensions #974

Open
FinnStokes opened this issue Mar 1, 2024 · 1 comment
Open

cost.LeastSquares fails with data with more than 2 dimensions #974

FinnStokes opened this issue Mar 1, 2024 · 1 comment

Comments

@FinnStokes
Copy link

For multidimensional x data formatted as a DxN array as described in the documentation, any D greater than 2 will cause iminuit to fail with the following error:

File "/usr/lib/python3.11/site-packages/iminuit/cost.py", line 1721, in _call
    y, yerror = self._masked.T[self._ndim :]
    ^^^^^^^^^
ValueError: too many values to unpack (expected 2)

See https://stackoverflow.com/questions/76127508/iminuit-high-dimension-multivariate-fit-problem

I believe this is because the following line assumes that x.ndim gives D:

self._ndim = x.ndim

However, with correctly formatted data, x.ndim can only give 1 or 2, and D is instead given by np.atleast_2d(x).shape[0] or simply x.shape[0] if the atleast_2d call that is already in the method is moved earlier.

@HDembinski
Copy link
Member

Thanks for reporting. There is indeed no test for 3D data and so the mistake slipped through. I will see how to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants