For a singular Gram matrix $B$ I need to find some matrix $A$ such that $AA'=B$. I can add a small multiple of identity matrix, but this could break upstream analysis (application is c-approximation to graph cut here).
Searching around I see "Rank-revealing VSV decomposition" (Ch 2 of UTV expansion pack) and modified Cholesky decomposition implemented here. However nothing readily available in Mathematica, any tips?
Example of failure:
g = RandomGraph[BernoulliGraphDistribution[20, .5]];
setupSDP[g_Graph] := Block[
Sequence[{n, activeVars, objective, m, constraint, A, a, b},
n = Length[
VertexList[g]]; activeVars = ReplaceAll[
EdgeList[g], UndirectedEdge[
Pattern[a,
Blank[]],
Pattern[b,
Blank[]]] -> A[a, b]]; objective = -Total[
Map[(1 - #)/2& , activeVars]]; m = Array[A, {n, n}];
m = UpperTriangularize[m] - DiagonalMatrix[
Diagonal[m]]; m = m + Transpose[m] + IdentityMatrix[n];
constraint =
VectorGreaterEqual[{m, 0}, {"SemidefiniteCone", n}]; {
objective, constraint, m}]];
{objective, constraint, matrix} = setupSDP[g];
solution =
matrix /.
SemidefiniteOptimization[objective, constraint,
Variables[matrix]];
CholeskyDecomposition[solution]
In[272]:= {ssqrt, d} = ResourceFunction["RationalCholeskyDecomposition"][solution]; Max[Abs[ssqrt . DiagonalMatrix[d] . Transpose[ssqrt] - solution]] Out[273]= 2.22045*10^-16
$\endgroup$