我对Eigen是个新手,我想用Eigen来解有界的线性最小二乘系统。Eigen网站上的例子很简单,但我不确定如何设置解决方案的界限。
示例代码如下:
#include <iostream>
#include <Eigen/Dense>
using namespace std;
using namespace Eigen;
int main()
{
MatrixXf A = MatrixXf::Random(3, 2);
cout << "Here is the matrix A:\n" << A << endl;
VectorXf b = VectorXf::Random(3);
cout << "Here is the right hand side b:\n" << b << endl;
cout << "The least-squares solution is:\n"
<< A.bdcSvd(ComputeThinU | ComputeThinV).solve(b) << endl;
}它是在求解Ax=b,我在寻找x有界处的解。例如,我正在寻找Ax=b的最佳解决方案,使0
发布于 2020-05-22 06:43:42
本质上,您正在寻找二次规划问题的解决方案:||Ax - b||^2_2 -> min,服从0 <= x <= 1(注意,不等式并不严格)。AFAIK,Eigen没有提供这种开箱即用的功能,但有很多其他库可以做到这一点。
发布于 2020-06-21 16:14:25
你就快到了。有了这样的界限,你只需要缩放无界最小二乘解x,如果它的范数大于界限:
double bound = 1;
if(x.norm() > bound)
x = x*bound/x.norm();https://stackoverflow.com/questions/61929161
复制相似问题