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);