使用scipy.optimize.minimize在numpy中求解多个方程式

时间:2022-11-18 21:25:52

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

我看到了解决最小化问题的解决方案,如下所示:Numpy:具有特定条件的线性系统。没有负面解决方案

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.

但我有'k'这样的最小化问题需要在某一点上解决。因此,我不想迭代每个'k',而是想知道是否有更好的方法在numpy中这样做?谢谢。

1 个解决方案

#1


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!

我也不认为这个答案中使用的方法是最快的。它使用了一个更复杂的算法,它适用于更广泛的情况。我会尝试nnls,它在解决时间和稳健性方面应该是优越的(在大多数情况下)!

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.

有可能,scrany的nnls的Fortran实现不是多线程的。在这种情况下,因为您可能有许多独立问题,所以您可以使用joblib轻松地并行解决它们。

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)

(如果你的问题可能在某种程度上相似,那么可能有更多的收益,但可能没有自己的实现,例如重用矩阵分解。但我不认为你想要追求它,因为它会变得复杂非常快)

#1


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!

我也不认为这个答案中使用的方法是最快的。它使用了一个更复杂的算法,它适用于更广泛的情况。我会尝试nnls,它在解决时间和稳健性方面应该是优越的(在大多数情况下)!

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.

有可能,scrany的nnls的Fortran实现不是多线程的。在这种情况下,因为您可能有许多独立问题,所以您可以使用joblib轻松地并行解决它们。

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)

(如果你的问题可能在某种程度上相似,那么可能有更多的收益,但可能没有自己的实现,例如重用矩阵分解。但我不认为你想要追求它,因为它会变得复杂非常快)