0

I see the solution to solve a minimization problem as suggested here: Numpy: Linear system with specific conditions. No negative solutions

But I have 'k' such minimization problems to be solved at a point. So instead of iterating through each of the 'k', I was wondering if there is a better way of doing this in numpy? Thanks.

Community
  • 1
  • 1
user1697058
  • 115
  • 1
  • 9

1 Answers1

1

If they are independent, iterating is the way to go and combining them would probably be slower.

I also don't think the approach used in this answer is the fastest one. It's using a much more complex algorithm needed, which is tailored for a much broader case. I would try nnls which should be superior (in most cases) in regards to solving-time and robustness!

It could be possible, that the Fortran-implementation of scipy's nnls is not multithreaded. In this case, because you might have many independent problems, you can easily solve them in parallel using joblib for example.

The only thing left to mention: if your problems are sparse, you should look for algorithms optimized for the sparse-case!

(In the case where your problems might be similar somehow, there is much more gain possible, but probably not without an own implementation which for example reuses matrix-factorizations. But i don't think you want to pursue this as it will get complex very fast)

sascha
  • 32,238
  • 6
  • 68
  • 110