0
votes

I'm new to Eigen and I'd like to use Eigen for solving linear least squares systems with bounds. The example on Eigen's site is straightforward but I'm not sure how to set bounds for the solution.

Here's the example code:

#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;
}

It's solving Ax=b. I'm looking for the solution where x is bounded. For example I'm looking for the best solution of Ax=b such that 0 < x < 1. What's the proper way to do this?

2

2 Answers

0
votes

Essentially, you are looking for a solution to a quadratic programming problem: ||Ax - b||^2_2 -> min, subject to 0 <= x <= 1 (note that inequalities are not strict). AFAIK, Eigen does not provide such functionality out of the box, but there are plenty of other libraries that can do that.

0
votes

You're almost there. With a bound like this, you only need to scale the unbounded least square solution, x, if it's norm is greater than the bound:

double bound = 1;
if(x.norm() > bound)
    x = x*bound/x.norm();