I want to factorize a matrix $a_{ij}$ as $$ a_{ij} = \sum_k u_{ik} v_{jk} $$ using variational method for some reason. That is, I want to minimize the cost function $$ F = \sum_{ij} b_{ij}^2 $$ with respect to $u_{ik}$ and $v_{jk}$ where $$ b_{ij} = \sum_k u_{ik} v_{jk} - a_{ij} $$ I use gradient descent to find the minimum, therefore I need to calculate the derivative of $F$ with respect to $u_{ik}$ and $v_{jk}$. These can be calculated very easily with hand for example $$ \frac{\partial F}{\partial u_{ik}} = 2 \sum_j b_{ij} v_{jk} $$ However, I want to see how Mathematica solves this quite typical problem so that I don't need to use hand to calculate a much more complex version of the problem.
The code I wrote is
KD[x_, y_] := KroneckerDelta[x, y]
u /: D[u[a_, b_], u[c_, d_], NonConstants -> {u}] := KD[a, c] KD[b, d]
v /: D[v[a_, b_], v[c_, d_], NonConstants -> {v}] := KD[a, c] KD[b, d]
b[i_, j_] := Sum[u[i, k] v[j, k], {k, Infinity}] - a[i, j]
F = Sum[b[i, j]^2, {i, Infinity}, {j, Infinity}];
$Assumptions = {i, j, k, i1, k1} \[Element] Integers && i > 0 && j > 0 && k > 0 && i1 > 0 && k1 > 0;
D[F, u[i1, k1], NonConstants -> {u}]
after a few minutes I got the result $$ \sum _i^{\infty } \sum _j^{\infty } 2 \left( \begin{array}{ll} \{ & \begin{array}{ll} v[j,\text{k1}] & i==\text{i1} \\ 0 & \text{True} \\ \end{array} \\ \end{array} \right) \left(-a[i,j]+\sum _k^{\infty } u[i,k] v[j,k]\right) $$
Is there an elegant way to evaluate the simple derivative $\frac{\partial F}{\partial u_{ik}}$ with Mathematica?
u
matrix be the identity and thev
matrix be the one being factored. I mention this to point out that you really need to state what it is you specifically you want to achieve in your factorization. Without that information there's not much that can be said. $\endgroup$ – Daniel Lichtblau Jun 26 '14 at 15:22