寻找 C++ 中的优化算法替换 Excel 求解器
由于 Excel Solver 在数千次优化上运行速度相当慢(原因是它使用电子表格作为界面),我试图在 C++ 中实现类似的(特定于问题的)求解器(使用 Visual Studio 2010,在 Win 上) 7 64 位平台)。我将通过 VBA 中的 Declare 语句包含 DLL,并且已经有这样做的经验,所以这不是问题。
我的问题是最小化经验数据与非线性但平滑的目标函数之间的平方误差之和,并且问题将包括非负性(X>=0)甚至正性约束(例如X>=0.00000001) ,其中 X 表示决策变量。
我正在寻找一个强大的、经过验证的实现。它可能是已建立的图书馆的一部分。 例如,我已经研究了 ALGLIB 的存储内容(请参阅 http://www.alglib.net/ optimization/),似乎他们的算法中只有一种接受有界约束。但我不知道它的价值是什么,这就是为什么我试图收集一些意见。
或者,另一方面,是否建议用这样的基本约束来增强 ALGLIB 的 Levenberg-Marquardt 算法,例如拒绝每个不满足我的约束的中间解决方案? (我猜这不会成功,但仍然值得一问)
since Excel Solver is quite slow to run on thousands of optimizations (the reason being that it uses the spreadsheet as interface), I'm trying to implement a similar (problem-specific) solver in C++ (with Visual Studio 2010, on a Win 7 64-bit platform). I would include the DLL via a Declare statement in VBA and already have experience in doing this, so this is not the problem.
My problem would be minimizing the sum of squared errors between empirical data and a target function which is non-linear but smooth, and the problem would include non-negativity (X>=0) or even positivity constraints (e.g. X>=0.00000001), with X denoting the decision variable.
I'm looking for a robust, proven implementation. It may be part of an established library.
For example, I've already looked into what ALGLIB has in store (see http://www.alglib.net/optimization/) and it seems only one of their algorithms accepts bounded constraints. But I don't know what it's worth, though, that's why I'm trying to gather some opinions.
Or, on another note, would it be advisable to augment ALGLIB's Levenberg-Marquardt algorithm with such basic constraints, for example by rejecting every intermediate solution that does not satisfy my constraints? (guess that won't do it, but it's still worth asking)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Levenberg-Marquardt 方法经过修改,增加了对不等式约束的支持。我知道一个实现这种算法的库:
levmar (GPL)。
如果您想修改现有算法,拒绝不好的解决方案是行不通的,优化可能会陷入困境。但您可以进行变量替换,例如确保 X > 0.1 您可以使用 t^2+0.1 代替 X。
我使用此方法作为程序中缺少内置框约束的解决方法。以下是 Peter Gans 的化学科学中的数据拟合的一段话,对其进行了更好的描述:
https://github.com/wojdyr/fityk/wiki/InequalityConstraints
There are modifications of the Levenberg-Marquardt method that add support for inequality constraints. I know about one library that implements such an algorithm:
levmar (GPL).
If you would like to modify an existing algorithm, rejecting bad solutions won't do, the optimization will likely get stuck. But you can make a variable substitution, e.g. to ensure that X > 0.1 you can use t^2+0.1 instead of X.
I use this method as a workaround for the lack of built-in box constraints in my program. Here is a quote from Data fitting in the chemical sciences by Peter Gans that describes it better:
https://github.com/wojdyr/fityk/wiki/InequalityConstraints
我们发现 OPTIF9 和 UNCMIN 是选择的标准方法。
您应该能够在库中链接它们,并从 C++ 调用它们,
如果你不想费心编译 Fortran。
对搜索空间施加限制的一种方法是转换参数,例如通过 logit 函数。
We find OPTIF9 and UNCMIN to be the standard methods of choice.
You should be able to link them in a library, and call them from C++,
if you don't want to bother compiling Fortran.
A way to put limits on the search space is to transform the parameters, such as by a logit function.
您是否研究过Microsoft Solver Foundation? Express 版本是免费的,并附带 .NET 4.0 dll。我发现它相当容易使用。另一方面,我不知道你说的问题有多大: Express 版本中的变量数量有一些限制。
Have you looked into the Microsoft Solver Foundation? The express edition is free, and comes with a .NET 4.0 dll. I found it fairly easy to use. On the other hand, I don't know how large of a problem you are talking: there are some limitations in the number of variables in the express edition.