多维优化/寻根/某事的算法
我有五个值,A、B、C、D 和 E。
给定约束 A + B + C + D + E = 1,以及五个函数 F(A)、F(B)、F(C)、F( D)、F(E),我需要求解 A 到 E,使得 F(A) = F(B) = F(C) = F(D) = F(E)。
为此使用的最佳算法/方法是什么?我不在乎是否必须自己写,我只是想知道在哪里看。
编辑:这些是非线性函数。除此之外,无法对它们进行表征。其中一些最终可能会从数据表中插入。
I have five values, A, B, C, D and E.
Given the constraint A + B + C + D + E = 1, and five functions F(A), F(B), F(C), F(D), F(E), I need to solve for A through E such that F(A) = F(B) = F(C) = F(D) = F(E).
What's the best algorithm/approach to use for this? I don't care if I have to write it myself, I would just like to know where to look.
EDIT: These are nonlinear functions. Beyond that, they can't be characterized. Some of them may eventually be interpolated from a table of data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
这个问题没有通用的答案。找到任何方程的解的求解器并不存在。正如兰斯·罗伯茨(Lance Roberts)所说,您必须更多地了解这些功能。只是几个例子
在解决问题之前,您确实需要更多地了解您正在研究的函数。
There is no general answer to this question. A solver finding the solution to any equation does not exist. As Lance Roberts already says, you have to know more about the functions. Just a few examples
Before you can solve the problem, you really need to know more about the function you're studying.
正如其他人已经发布的那样,我们确实需要有关这些功能的更多信息。然而,考虑到这一点,我们仍然可以尝试使用标准非线性编程工具箱来解决以下松弛问题。
最小 k
圣
A + B + C + D + E = 1
F1(A) - k = 0
F2(B) - k = 0
F3(C) -k = 0
F4(D) - k = 0
F5(E) -k = 0
现在我们可以用任何我们希望的方式来解决这个问题,例如惩罚方法
min k + mu*sum(Fi(x_i) - k)^2
圣
A+B+C+D+E = 1
或直接的 SQP 或内点法。
更多细节,我可以帮助建议一个好的方法。
米
As others have already posted, we do need some more information on the functions. However, given that, we can still try to solve the following relaxation with a standard non-linear programming toolbox.
min k
st.
A + B + C + D + E = 1
F1(A) - k = 0
F2(B) - k = 0
F3(C) -k = 0
F4(D) - k = 0
F5(E) -k = 0
Now we can solve this in any manner we wish, such as penalty method
min k + mu*sum(Fi(x_i) - k)^2
st
A+B+C+D+E = 1
or a straightforward SQP or interior-point method.
More details and I can help advise as to a good method.
m
这些函数都随着它们的参数单调递增。除此之外,无法对它们进行表征。行之有效的方法是:
1) 从 A = B = C = D = E = 1/5 开始
2) 计算 F1(A) 到 F5(E),并重新计算 A 到 E,使每个函数等于总和除以 5(平均值)。
3) 重新调整新的 A 到 E,使它们的总和为 1,并重新计算 F1 到 F5。
4) 重复直到满意为止。
它的收敛速度快得惊人——只需几次迭代。当然,每次迭代都需要第 2 步找到 5 个根。
The functions are all monotonically increasing with their argument. Beyond that, they can't be characterized. The approach that worked turned out to be:
1) Start with A = B = C = D = E = 1/5
2) Compute F1(A) through F5(E), and recalculate A through E such that each function equals that sum divided by 5 (the average).
3) Rescale the new A through E so that they all sum to 1, and recompute F1 through F5.
4) Repeat until satisfied.
It converges surprisingly fast - just a few iterations. Of course, each iteration requires 5 root finds for step 2.
方程的一种解
是取 A、B、C、D 和 E 都等于 1/5。不确定这是否是您想要的...
在约翰的评论后添加(谢谢!)
假设第二个方程应为 F1(A) = F2(B) = F3(C) = F4( D) = F5(E),我会使用 Newton-Raphson 方法(参见 Martijn 的回答)。您可以通过设置 E = 1 - A - B - C - D 来消除一个变量。在迭代的每一步,您都需要求解 4x4 系统。最大的问题可能是从哪里开始迭代。一种可能性是从随机点开始,进行一些迭代,如果没有任何进展,则选择另一个随机点并重新开始。
请记住,如果您确实对该函数一无所知,那么就不需要解决方案。
One solution of the equations
is to take A, B, C, D and E all equal to 1/5. Not sure though whether that is what you want ...
Added after John's comment (thanks!)
Assuming the second equation should read F1(A) = F2(B) = F3(C) = F4(D) = F5(E), I'd use the Newton-Raphson method (see Martijn's answer). You can eliminate one variable by setting E = 1 - A - B - C - D. At every step of the iteration you need to solve a 4x4 system. The biggest problem is probably where to start the iteration. One possibility is to start at a random point, do some iterations, and if you're not getting anywhere, pick another random point and start again.
Keep in mind that if you really don't know anything about the function then there need not be a solution.
ALGENCAN(TANGO 的一部分)非常好。也有 Python 绑定。
http://www.ime.usp.br/~egbirgin/tango/ codes.php - “一般非线性编程根本不使用矩阵操作,因此能够用适度的计算机时间解决非常大的问题。一般算法是增强拉格朗日类型......”
http://pypi.python.org/pypi/TANGO%20Project%20 -%20ALGENCAN/1.0
ALGENCAN (part of TANGO) is really nice. There are Python bindings, too.
http://www.ime.usp.br/~egbirgin/tango/codes.php - " general nonlinear programming that does not use matrix manipulations at all and, so, is able to solve extremely large problems with moderate computer time. The general algorithm is of Augmented Lagrangian type ... "
http://pypi.python.org/pypi/TANGO%20Project%20-%20ALGENCAN/1.0
谷歌 OPTIF9 或 ALLUNC。我们将它们用于一般优化。
Google OPTIF9 or ALLUNC. We use these for general optimization.
您可以使用其他人提到的标准搜索技术。您在搜索时可以利用它进行一些优化。
首先,你只需要解A、B、C、D,因为1-E = A+B+C+D。
其次,你有 F(A) = F(B) = F(C) = F(D),那么你可以搜索 A。一旦你得到 F(A),你就可以解决 B、C、D,如果是可能的。如果无法求解函数,则需要继续搜索每个变量,但现在搜索的范围有限,因为 A+B+C+D <= 1。
如果您的搜索是离散且有限的,则上述优化应该可以很好地发挥作用。
You could use standard search technic as the others mentioned. There are a few optimization you could make use of it while doing the search.
First of all, you only need to solve A,B,C,D because 1-E = A+B+C+D.
Second, you have F(A) = F(B) = F(C) = F(D), then you can search for A. Once you get F(A), you could solve B, C, D if that is possible. If it is not possible to solve the functions, you need to continue search each variable, but now you have a limited range to search for because A+B+C+D <= 1.
If your search is discrete and finite, the above optimizations should work reasonable well.
我会首先尝试粒子群优化。它非常容易实施和调整。请参阅 Wiki 页面。
I would try Particle Swarm Optimization first. It is very easy to implement and tweak. See the Wiki page for it.