Suppose I have a linear equation, $X.M=A$, for given matrices $M$ and $A$. I can use FindInstance to produce a solution $X$.
How can I add the constraint that $X$ has the least rank?
Indeed, I could add Det[$X$]==0 in FindInstance when $X$ is square, and iterate. But, $X$ may be non-square.
Example 1:
Suppose
M={{0, 1, 0, 0, 1, 1}, {0, 1, 0, 1, 1, 0}, {0, 1, 1, 0, 0, 1}, {0, 1, 1,
1, 0, 0}, {1, 0, 0, 0, 1, 1}, {1, 0, 0, 1, 1, 0}, {1, 0, 1, 0, 0,
1}, {1, 0, 1, 1, 0, 0}}
and
A={{1, 0, 1/2, 1/2, 1/2, 1/2}, {0, 1, 1/2, 1/2, 1/2, 1/2}, {1/2, 1/2, 1,
1/2, 0, 1/2}, {1/2, 1/2, 1/2, 1, 1/2, 0}, {1/2, 1/2, 0, 1/2, 1, 1/
2}, {1/2, 1/2, 1/2, 0, 1/2, 1}}
Then,
X1 = Array[f, {Dimensions[[A]], Dimensions[M][[1]]}];
X1 /. FindInstance[
X1 . M == A,
Flatten[X], NonNegativeReals][[1]]
returns
X1={{0, 0, 0, 0, 0, 1/2, 1/2, 0}, {0, 1/2, 1/2, 0, 0, 0, 0, 0}, {0, 0, 1/
2, 0, 0, 0, 0, 1/2}, {0, 1/2, 0, 0, 0, 0, 0, 1/2}, {1/2, 0, 0, 0, 0,
1/2, 0, 0}, {0, 0, 1/2, 0, 1/2, 0, 0, 0}};
X//MatrixRank
6
There is, however, a solution of rank four, namely,
X2={{0, 0, 0, 0, 1/2, 0, 0, 1/2}, {0, 1/2, 1/2, 0, 0, 0, 0, 0}, {0, 0, 1/
2, 0, 0, 0, 0, 1/2}, {0, 1/2, 0, 0, 0, 0, 0, 1/2}, {0, 1/2, 0, 0, 1/
2, 0, 0, 0}, {0, 0, 1/2, 0, 1/2, 0, 0, 0}};
X2//MatrixRank
4
How can I enforce FindInstance to look for a solution with the lowest rank, i.e., returns X2 rather than X1?
The only thing I got to work is
FindInstance[
X1 . M == A&&Det[X1]==0,
Flatten[X], NonNegativeReals]
But, this works only for square matrices. In general, I encounter non-square ones.
As suggested in the comments, LeastSquares provides a way to find the lowest rank solution. However, as in the example above, it's important that the matrix entries of the solution are nonnegative. Here is an example showing the difficulty with the LeastSquates.
Example 2:
Let
M={{0, 0, 1, 1}, {0, 1, 1, 0}, {1, 0, 0, 1}, {1, 1, 0, 0}}
and
A={{1, 0, 0, 1}, {1, 1, 0, 0}, {0, 1, 1, 0}, {0, 0, 1, 1}}
Then, LeastSquares returns solutions with negative entries:
X={{1/4, -(1/4), 3/4, 1/4}, {-(1/4), 1/4, 1/4, 3/4}, {1/4, 3/4, -(1/4),
1/4}, {3/4, 1/4, 1/4, -(1/4)}}
PseudoInverseis what you're looking for. – Ulrich Neumann Jun 20 '22 at 13:49LeastSquaresis a possibility. – Ulrich Neumann Jun 20 '22 at 13:59A . PseudoInverse[M]suit your needs? – J. M.'s missing motivation Jun 20 '22 at 14:07LeastSquares[]/PseudoInverse[]is unable to give a solution with nonnegative entries (if you have one). – J. M.'s missing motivation Jun 20 '22 at 14:27m = {{0, 0, 1, 1}, {0, 1, 1, 0}, {1, 0, 0, 1}, {1, 1, 0, 0}}; a = {{1, 0, 0, 1}, {1, 1, 0, 0}, {0, 1, 1, 0}, {0, 0, 1, 1}}; pinv = PseudoInverse[Transpose[m]]; ns = First[NullSpace[Transpose[m]]]; Reduce[Thread[Flatten[pinv . Transpose[a] + KroneckerProduct[ns, ConstantArray[t, Length[a]]]] > 0], t]. – J. M.'s missing motivation Jun 20 '22 at 15:01X1={{0, 0, 1, 0}, {0, 0, 0, 1}, {0, 1, 0, 0}, {1, 0, 0, 0}}which is of rank 4. – Farid Shahandeh Jun 20 '22 at 15:11