Closed MarkWieczorek closed 1 month ago
Do you have any means to build the current main by any chance? Otherwise please paste the array somewhere online like pastebin or a gist and I'll see if the result of the latest version (#21021) is in accordance with your expectations.
Build scipy? No. Sorry. Not that much free time...
I'll upload the file somewhere today. However, given that this appears to be a numerical resolution issue, I wonder if you just took any matrix A and vector b and divided them by 1.e20 if that would be sufficient to reproduce this.
Build scipy? No. Sorry. Not that much free time...
Same applies to us. Hence my question.
I wonder if you just took any matrix A and vector b and divided them by 1.e20 if that would be sufficient to reproduce this.
We are trying to find if the new code solves, not the old code fails. Otherwise we have a number of examples for the old code to fail and we fixed them. We should see if it also fixed your problem.
Here are the data, and I updated the original post with simple script to reproduce this.
On the current main I get
-2.4193018654733958e-21 3.943646586725562e-21
-1.4210278995247266e-08 1.217756814911735e-08
298 4.3438564761143895e-08
298 4.343856476114391e-08
298 4.3438564761143895e-08
So it looks like it is working properly, but as a recommendation, it is always better to scale your data because it improves the conditioning.
To confirm:
This is a bug with version 1.12, 1.13 and 1.14. The bug will be fixed in version 1.15.
That's correct.
Describe your issue.
In scipy 1.12, a python version of the NNLS (non-negative least squares) routine replaced the tried and tested fortran version. Unfortunately, the behavior of the new routine (which claims to be faster) is sometimes inconsistent with the old routine, and the new routine gives no indication of when the results are unreliable.
Description of problem
I am trying to solve the problem
min $$||Ax - b||$$
with the constraint that all elements of x are non-negative. With A having a shape (n, m), a maximum of n elements of x will be non-zero.
For my problem, the matrix A has shape (1074, 1257), the minimum and maximum values of the elements of A are -2.4193018654733958e-21, and 3.943646586725562e-21, and the minimum and maximum values of b are -1.4210278995247266e-08 and 1.217756814911735e-08.
calling (using scipy 1.14.1)
yields a solution vector m that is identically zero.
Since A and b were expressed in SI units of Teslas, I decided to convert to nT instead
This returns a solution vector that has 102 non-zero elements.
Noting that the elements of A were small, I then tried to normalize A and b by the maximum value of A
This returns a solution vector that has 298 non-zero elements.
Next, I compared with the old Fortran based routine in scipy 1.11. For this, all three tests above returned the exact same answer with 298 non-zero elements in the solution vector.
Conclusion
Related to https://github.com/scipy/scipy/issues/21484 Ping @ilayn
Reproducing Code Example
Error message
SciPy/NumPy/Python version and system information