Simon
Simon

Reputation: 151

Solving a least squares matrix having constrained the results

I have a rectangular matrix thus:

1, 3, 2, 4, n..
4, 2, 1, 5, n..
n..

and a vector thus:
1, 2, 5, 6, 7, n..

I need to solve the least-squares equation for all columns in the matrix, but I want to constrain the results such that all answers are greater than zero.

I've added the Math.NET package and got as far as
matrix.QR().Solve(...

Presumably there is some way to iteratively solve this but there doesn't appear to be a way to specify constraints/conditions to the Solve method, and I'm not sure what other method(s) I should use.

Partial code added below:

//compounds is Dictionary<int, List<double>> 
var xdata = compounds.Values.Select(v => v.ToArray()).ToArray();
var ydata = new DenseVector(someKnownValues.ToArray());
var matrix = DenseMatrix.OfColumns(ydata.Count(), xdata.Count(), xdata);
var factors = matrix.QR().Solve(ydata);

Upvotes: 3

Views: 1396

Answers (1)

Christoph R&#252;egg
Christoph R&#252;egg

Reputation: 4736

Unfortunately solving non-negative (or positive) least squares problems is not supported by Math.NET Numerics out of the box.

Some further information and an algorithm: Non-negative least squares (Wikipedia)

Upvotes: 4

Related Questions