How to optimize a non-linear least squares energy with respect to the non-zeros of a sparse matrix?
$begingroup$
I have an energy I'd like to minimize of the form:
$E(G) = |underbrace{X - Y G^T L G B}_{f(G)}|_F^2$
where $X,Y,B$ are dense matrices and $G,L$ are sparse matrices ($G^TLG$ is also sparse), $|M|_F^2$ computes the squared Frobenius norm of the matrix $M$.
I'd like to compute quantities such as $partial f/partial G$ (or $partial^2 E/partial G^2$) to use Gauss-Newton's (or Newton's) method, but I only care about changes to $G$ that maintain its sparsity pattern. That is, suppose $G$ is a function of the non-zero values collected in a vector $g$ via, say, $G = mathop{sparse}(i,j,g)$ where $i,j$ are lists of subscript indices corresponding to values in $g$. Then I'd really like to compute $partial f/partial g$.
Eventually I'm programming this and would like to avoid computing $partial f/partial G$ as a dense matrix/tensor.
Is there's a nice (reduced) expression for $partial f/partial g$?
If not, what's the best way to use automatic differentiation to conduct this optimization? I'm having trouble formulating this in the right way to use the libraries I found.
derivatives optimization tensors least-squares sparse-matrices
$endgroup$
add a comment |
$begingroup$
I have an energy I'd like to minimize of the form:
$E(G) = |underbrace{X - Y G^T L G B}_{f(G)}|_F^2$
where $X,Y,B$ are dense matrices and $G,L$ are sparse matrices ($G^TLG$ is also sparse), $|M|_F^2$ computes the squared Frobenius norm of the matrix $M$.
I'd like to compute quantities such as $partial f/partial G$ (or $partial^2 E/partial G^2$) to use Gauss-Newton's (or Newton's) method, but I only care about changes to $G$ that maintain its sparsity pattern. That is, suppose $G$ is a function of the non-zero values collected in a vector $g$ via, say, $G = mathop{sparse}(i,j,g)$ where $i,j$ are lists of subscript indices corresponding to values in $g$. Then I'd really like to compute $partial f/partial g$.
Eventually I'm programming this and would like to avoid computing $partial f/partial G$ as a dense matrix/tensor.
Is there's a nice (reduced) expression for $partial f/partial g$?
If not, what's the best way to use automatic differentiation to conduct this optimization? I'm having trouble formulating this in the right way to use the libraries I found.
derivatives optimization tensors least-squares sparse-matrices
$endgroup$
$begingroup$
Are you seeking $frac{partial E(G)}{partial G}$ or $frac{partial f(G)}{partial G}$, where $E(G)$ is a scalar and $f(G)$ is a matrix? If you are looking for $frac{partial f(G)}{partial G}$, then it will be 4th order tensor (and don't think it is really needed for the optimization). I think $frac{partial E(G)}{partial G}$ should suffice your need...
$endgroup$
– user550103
Jan 8 at 5:44
$begingroup$
I'm interested in $d f(G(g))/d g$
$endgroup$
– Alec Jacobson
Jan 8 at 18:20
add a comment |
$begingroup$
I have an energy I'd like to minimize of the form:
$E(G) = |underbrace{X - Y G^T L G B}_{f(G)}|_F^2$
where $X,Y,B$ are dense matrices and $G,L$ are sparse matrices ($G^TLG$ is also sparse), $|M|_F^2$ computes the squared Frobenius norm of the matrix $M$.
I'd like to compute quantities such as $partial f/partial G$ (or $partial^2 E/partial G^2$) to use Gauss-Newton's (or Newton's) method, but I only care about changes to $G$ that maintain its sparsity pattern. That is, suppose $G$ is a function of the non-zero values collected in a vector $g$ via, say, $G = mathop{sparse}(i,j,g)$ where $i,j$ are lists of subscript indices corresponding to values in $g$. Then I'd really like to compute $partial f/partial g$.
Eventually I'm programming this and would like to avoid computing $partial f/partial G$ as a dense matrix/tensor.
Is there's a nice (reduced) expression for $partial f/partial g$?
If not, what's the best way to use automatic differentiation to conduct this optimization? I'm having trouble formulating this in the right way to use the libraries I found.
derivatives optimization tensors least-squares sparse-matrices
$endgroup$
I have an energy I'd like to minimize of the form:
$E(G) = |underbrace{X - Y G^T L G B}_{f(G)}|_F^2$
where $X,Y,B$ are dense matrices and $G,L$ are sparse matrices ($G^TLG$ is also sparse), $|M|_F^2$ computes the squared Frobenius norm of the matrix $M$.
I'd like to compute quantities such as $partial f/partial G$ (or $partial^2 E/partial G^2$) to use Gauss-Newton's (or Newton's) method, but I only care about changes to $G$ that maintain its sparsity pattern. That is, suppose $G$ is a function of the non-zero values collected in a vector $g$ via, say, $G = mathop{sparse}(i,j,g)$ where $i,j$ are lists of subscript indices corresponding to values in $g$. Then I'd really like to compute $partial f/partial g$.
Eventually I'm programming this and would like to avoid computing $partial f/partial G$ as a dense matrix/tensor.
Is there's a nice (reduced) expression for $partial f/partial g$?
If not, what's the best way to use automatic differentiation to conduct this optimization? I'm having trouble formulating this in the right way to use the libraries I found.
derivatives optimization tensors least-squares sparse-matrices
derivatives optimization tensors least-squares sparse-matrices
edited Jan 9 at 3:07
Alec Jacobson
asked Jan 7 at 19:41
Alec JacobsonAlec Jacobson
270111
270111
$begingroup$
Are you seeking $frac{partial E(G)}{partial G}$ or $frac{partial f(G)}{partial G}$, where $E(G)$ is a scalar and $f(G)$ is a matrix? If you are looking for $frac{partial f(G)}{partial G}$, then it will be 4th order tensor (and don't think it is really needed for the optimization). I think $frac{partial E(G)}{partial G}$ should suffice your need...
$endgroup$
– user550103
Jan 8 at 5:44
$begingroup$
I'm interested in $d f(G(g))/d g$
$endgroup$
– Alec Jacobson
Jan 8 at 18:20
add a comment |
$begingroup$
Are you seeking $frac{partial E(G)}{partial G}$ or $frac{partial f(G)}{partial G}$, where $E(G)$ is a scalar and $f(G)$ is a matrix? If you are looking for $frac{partial f(G)}{partial G}$, then it will be 4th order tensor (and don't think it is really needed for the optimization). I think $frac{partial E(G)}{partial G}$ should suffice your need...
$endgroup$
– user550103
Jan 8 at 5:44
$begingroup$
I'm interested in $d f(G(g))/d g$
$endgroup$
– Alec Jacobson
Jan 8 at 18:20
$begingroup$
Are you seeking $frac{partial E(G)}{partial G}$ or $frac{partial f(G)}{partial G}$, where $E(G)$ is a scalar and $f(G)$ is a matrix? If you are looking for $frac{partial f(G)}{partial G}$, then it will be 4th order tensor (and don't think it is really needed for the optimization). I think $frac{partial E(G)}{partial G}$ should suffice your need...
$endgroup$
– user550103
Jan 8 at 5:44
$begingroup$
Are you seeking $frac{partial E(G)}{partial G}$ or $frac{partial f(G)}{partial G}$, where $E(G)$ is a scalar and $f(G)$ is a matrix? If you are looking for $frac{partial f(G)}{partial G}$, then it will be 4th order tensor (and don't think it is really needed for the optimization). I think $frac{partial E(G)}{partial G}$ should suffice your need...
$endgroup$
– user550103
Jan 8 at 5:44
$begingroup$
I'm interested in $d f(G(g))/d g$
$endgroup$
– Alec Jacobson
Jan 8 at 18:20
$begingroup$
I'm interested in $d f(G(g))/d g$
$endgroup$
– Alec Jacobson
Jan 8 at 18:20
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
Consider the normal vectorization operation applied to the sparse matrix $G$. Now define a projection matrix $P$ which omits the zero elements to recover what you've denoted as the $g$-vector. So we have
$$eqalign{
g_{vec} &= {rm vec}(G) = P^Tg cr
g &= P,g_{vec} = PP^Tg cr
I &= PP^T cr
}$$
As a concrete example of the projection matrix consider
$$eqalign{
G &= pmatrix{1&4cr 0&0},quad g_{vec}=pmatrix{1cr 0cr 4cr 0},quad g=pmatrix{1cr 4} cr
P &= pmatrix{1&0&0&0cr0&0&1&0},quad P^T=pmatrix{1&0cr 0&0cr 0&1cr 0&0} cr
}$$Define the matrix
$$F = (YG^TLGB - X) = -f$$
Write the energy in terms of $F$ and find its differential in terms of the differential $dg$.
$$eqalign{
{mathcal E} &= |F|^2_F = {rm Tr}(F^TF) = F:F {quadrm Big(Frobenius,productBig)} cr
d{mathcal E}
&= 2F:dF cr
&= 2F:big(Y,dG^T,LGB+YG^TL,dG,Bbig) cr
&= big(2LGBF^TY + 2L^TGY^TFB^Tbig):dG cr
&= 2{,rm vec}big(2LGBF^TY + 2L^TGY^TFB^Tbig):{rm vec}(dG) cr
&= 2Big((Y^TFB^Totimes L),g_{vec} + (BF^TYotimes L^T),g_{vec}Big):dg_{vec} cr
&= 2Big(Y^TFB^Totimes L + BF^TYotimes L^TBig)P^Tg:P^T,dg cr
&= 2PBig(Y^TFB^Totimes L + BF^TYotimes L^TBig)P^Tg:dg cr
}$$
So the gradient is
$$eqalign{
frac{partial {mathcal E}}{partial g} &= 2PBig(Y^TFB^Totimes L+BF^TYotimes L^TBig)P^Tg cr
}$$
Finding the Hessian is not worth the additional effort. Just use a gradient-based method,
e.g. Polak-Ribiere, Barzilai-Borwein, etc.
$endgroup$
$begingroup$
Thanks. I actually already had the gradient, but your derivation is very nice. I am interested in $df/dg$ in the hopes of doing Gauss-Newton (currently gradient-based methods I've tried are quite slow).
$endgroup$
– Alec Jacobson
Jan 9 at 3:07
1
$begingroup$
@AlecJacobson The gradient of a matrix wrt a vector is a 3rd order tensor. But by flattening the matrix into a vector, i.e. $,f_{vec}={rm vec}(F),,$ the gradient can be written as a matrix $$ frac{partial f_{vec}}{partial g} = (B^TG^TL^Totimes Y)KP^T + (B^Totimes YG^TL)P^T $$ where $K$ is the Commutation Matrix associated with the Kronecker product.
$endgroup$
– greg
Jan 9 at 6:21
$begingroup$
Thanks, again. Should this expression be multiplied by $g$ on the right?
$endgroup$
– Alec Jacobson
Jan 9 at 7:22
1
$begingroup$
@AlecJacobson No, the gradient is a matrix, not a vector.
$endgroup$
– greg
Jan 9 at 8:47
$begingroup$
Right. I confused myself. f is linear in g, thus the $d f /d g$ is a constant matrix.
$endgroup$
– Alec Jacobson
Jan 9 at 15:52
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3065413%2fhow-to-optimize-a-non-linear-least-squares-energy-with-respect-to-the-non-zeros%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Consider the normal vectorization operation applied to the sparse matrix $G$. Now define a projection matrix $P$ which omits the zero elements to recover what you've denoted as the $g$-vector. So we have
$$eqalign{
g_{vec} &= {rm vec}(G) = P^Tg cr
g &= P,g_{vec} = PP^Tg cr
I &= PP^T cr
}$$
As a concrete example of the projection matrix consider
$$eqalign{
G &= pmatrix{1&4cr 0&0},quad g_{vec}=pmatrix{1cr 0cr 4cr 0},quad g=pmatrix{1cr 4} cr
P &= pmatrix{1&0&0&0cr0&0&1&0},quad P^T=pmatrix{1&0cr 0&0cr 0&1cr 0&0} cr
}$$Define the matrix
$$F = (YG^TLGB - X) = -f$$
Write the energy in terms of $F$ and find its differential in terms of the differential $dg$.
$$eqalign{
{mathcal E} &= |F|^2_F = {rm Tr}(F^TF) = F:F {quadrm Big(Frobenius,productBig)} cr
d{mathcal E}
&= 2F:dF cr
&= 2F:big(Y,dG^T,LGB+YG^TL,dG,Bbig) cr
&= big(2LGBF^TY + 2L^TGY^TFB^Tbig):dG cr
&= 2{,rm vec}big(2LGBF^TY + 2L^TGY^TFB^Tbig):{rm vec}(dG) cr
&= 2Big((Y^TFB^Totimes L),g_{vec} + (BF^TYotimes L^T),g_{vec}Big):dg_{vec} cr
&= 2Big(Y^TFB^Totimes L + BF^TYotimes L^TBig)P^Tg:P^T,dg cr
&= 2PBig(Y^TFB^Totimes L + BF^TYotimes L^TBig)P^Tg:dg cr
}$$
So the gradient is
$$eqalign{
frac{partial {mathcal E}}{partial g} &= 2PBig(Y^TFB^Totimes L+BF^TYotimes L^TBig)P^Tg cr
}$$
Finding the Hessian is not worth the additional effort. Just use a gradient-based method,
e.g. Polak-Ribiere, Barzilai-Borwein, etc.
$endgroup$
$begingroup$
Thanks. I actually already had the gradient, but your derivation is very nice. I am interested in $df/dg$ in the hopes of doing Gauss-Newton (currently gradient-based methods I've tried are quite slow).
$endgroup$
– Alec Jacobson
Jan 9 at 3:07
1
$begingroup$
@AlecJacobson The gradient of a matrix wrt a vector is a 3rd order tensor. But by flattening the matrix into a vector, i.e. $,f_{vec}={rm vec}(F),,$ the gradient can be written as a matrix $$ frac{partial f_{vec}}{partial g} = (B^TG^TL^Totimes Y)KP^T + (B^Totimes YG^TL)P^T $$ where $K$ is the Commutation Matrix associated with the Kronecker product.
$endgroup$
– greg
Jan 9 at 6:21
$begingroup$
Thanks, again. Should this expression be multiplied by $g$ on the right?
$endgroup$
– Alec Jacobson
Jan 9 at 7:22
1
$begingroup$
@AlecJacobson No, the gradient is a matrix, not a vector.
$endgroup$
– greg
Jan 9 at 8:47
$begingroup$
Right. I confused myself. f is linear in g, thus the $d f /d g$ is a constant matrix.
$endgroup$
– Alec Jacobson
Jan 9 at 15:52
add a comment |
$begingroup$
Consider the normal vectorization operation applied to the sparse matrix $G$. Now define a projection matrix $P$ which omits the zero elements to recover what you've denoted as the $g$-vector. So we have
$$eqalign{
g_{vec} &= {rm vec}(G) = P^Tg cr
g &= P,g_{vec} = PP^Tg cr
I &= PP^T cr
}$$
As a concrete example of the projection matrix consider
$$eqalign{
G &= pmatrix{1&4cr 0&0},quad g_{vec}=pmatrix{1cr 0cr 4cr 0},quad g=pmatrix{1cr 4} cr
P &= pmatrix{1&0&0&0cr0&0&1&0},quad P^T=pmatrix{1&0cr 0&0cr 0&1cr 0&0} cr
}$$Define the matrix
$$F = (YG^TLGB - X) = -f$$
Write the energy in terms of $F$ and find its differential in terms of the differential $dg$.
$$eqalign{
{mathcal E} &= |F|^2_F = {rm Tr}(F^TF) = F:F {quadrm Big(Frobenius,productBig)} cr
d{mathcal E}
&= 2F:dF cr
&= 2F:big(Y,dG^T,LGB+YG^TL,dG,Bbig) cr
&= big(2LGBF^TY + 2L^TGY^TFB^Tbig):dG cr
&= 2{,rm vec}big(2LGBF^TY + 2L^TGY^TFB^Tbig):{rm vec}(dG) cr
&= 2Big((Y^TFB^Totimes L),g_{vec} + (BF^TYotimes L^T),g_{vec}Big):dg_{vec} cr
&= 2Big(Y^TFB^Totimes L + BF^TYotimes L^TBig)P^Tg:P^T,dg cr
&= 2PBig(Y^TFB^Totimes L + BF^TYotimes L^TBig)P^Tg:dg cr
}$$
So the gradient is
$$eqalign{
frac{partial {mathcal E}}{partial g} &= 2PBig(Y^TFB^Totimes L+BF^TYotimes L^TBig)P^Tg cr
}$$
Finding the Hessian is not worth the additional effort. Just use a gradient-based method,
e.g. Polak-Ribiere, Barzilai-Borwein, etc.
$endgroup$
$begingroup$
Thanks. I actually already had the gradient, but your derivation is very nice. I am interested in $df/dg$ in the hopes of doing Gauss-Newton (currently gradient-based methods I've tried are quite slow).
$endgroup$
– Alec Jacobson
Jan 9 at 3:07
1
$begingroup$
@AlecJacobson The gradient of a matrix wrt a vector is a 3rd order tensor. But by flattening the matrix into a vector, i.e. $,f_{vec}={rm vec}(F),,$ the gradient can be written as a matrix $$ frac{partial f_{vec}}{partial g} = (B^TG^TL^Totimes Y)KP^T + (B^Totimes YG^TL)P^T $$ where $K$ is the Commutation Matrix associated with the Kronecker product.
$endgroup$
– greg
Jan 9 at 6:21
$begingroup$
Thanks, again. Should this expression be multiplied by $g$ on the right?
$endgroup$
– Alec Jacobson
Jan 9 at 7:22
1
$begingroup$
@AlecJacobson No, the gradient is a matrix, not a vector.
$endgroup$
– greg
Jan 9 at 8:47
$begingroup$
Right. I confused myself. f is linear in g, thus the $d f /d g$ is a constant matrix.
$endgroup$
– Alec Jacobson
Jan 9 at 15:52
add a comment |
$begingroup$
Consider the normal vectorization operation applied to the sparse matrix $G$. Now define a projection matrix $P$ which omits the zero elements to recover what you've denoted as the $g$-vector. So we have
$$eqalign{
g_{vec} &= {rm vec}(G) = P^Tg cr
g &= P,g_{vec} = PP^Tg cr
I &= PP^T cr
}$$
As a concrete example of the projection matrix consider
$$eqalign{
G &= pmatrix{1&4cr 0&0},quad g_{vec}=pmatrix{1cr 0cr 4cr 0},quad g=pmatrix{1cr 4} cr
P &= pmatrix{1&0&0&0cr0&0&1&0},quad P^T=pmatrix{1&0cr 0&0cr 0&1cr 0&0} cr
}$$Define the matrix
$$F = (YG^TLGB - X) = -f$$
Write the energy in terms of $F$ and find its differential in terms of the differential $dg$.
$$eqalign{
{mathcal E} &= |F|^2_F = {rm Tr}(F^TF) = F:F {quadrm Big(Frobenius,productBig)} cr
d{mathcal E}
&= 2F:dF cr
&= 2F:big(Y,dG^T,LGB+YG^TL,dG,Bbig) cr
&= big(2LGBF^TY + 2L^TGY^TFB^Tbig):dG cr
&= 2{,rm vec}big(2LGBF^TY + 2L^TGY^TFB^Tbig):{rm vec}(dG) cr
&= 2Big((Y^TFB^Totimes L),g_{vec} + (BF^TYotimes L^T),g_{vec}Big):dg_{vec} cr
&= 2Big(Y^TFB^Totimes L + BF^TYotimes L^TBig)P^Tg:P^T,dg cr
&= 2PBig(Y^TFB^Totimes L + BF^TYotimes L^TBig)P^Tg:dg cr
}$$
So the gradient is
$$eqalign{
frac{partial {mathcal E}}{partial g} &= 2PBig(Y^TFB^Totimes L+BF^TYotimes L^TBig)P^Tg cr
}$$
Finding the Hessian is not worth the additional effort. Just use a gradient-based method,
e.g. Polak-Ribiere, Barzilai-Borwein, etc.
$endgroup$
Consider the normal vectorization operation applied to the sparse matrix $G$. Now define a projection matrix $P$ which omits the zero elements to recover what you've denoted as the $g$-vector. So we have
$$eqalign{
g_{vec} &= {rm vec}(G) = P^Tg cr
g &= P,g_{vec} = PP^Tg cr
I &= PP^T cr
}$$
As a concrete example of the projection matrix consider
$$eqalign{
G &= pmatrix{1&4cr 0&0},quad g_{vec}=pmatrix{1cr 0cr 4cr 0},quad g=pmatrix{1cr 4} cr
P &= pmatrix{1&0&0&0cr0&0&1&0},quad P^T=pmatrix{1&0cr 0&0cr 0&1cr 0&0} cr
}$$Define the matrix
$$F = (YG^TLGB - X) = -f$$
Write the energy in terms of $F$ and find its differential in terms of the differential $dg$.
$$eqalign{
{mathcal E} &= |F|^2_F = {rm Tr}(F^TF) = F:F {quadrm Big(Frobenius,productBig)} cr
d{mathcal E}
&= 2F:dF cr
&= 2F:big(Y,dG^T,LGB+YG^TL,dG,Bbig) cr
&= big(2LGBF^TY + 2L^TGY^TFB^Tbig):dG cr
&= 2{,rm vec}big(2LGBF^TY + 2L^TGY^TFB^Tbig):{rm vec}(dG) cr
&= 2Big((Y^TFB^Totimes L),g_{vec} + (BF^TYotimes L^T),g_{vec}Big):dg_{vec} cr
&= 2Big(Y^TFB^Totimes L + BF^TYotimes L^TBig)P^Tg:P^T,dg cr
&= 2PBig(Y^TFB^Totimes L + BF^TYotimes L^TBig)P^Tg:dg cr
}$$
So the gradient is
$$eqalign{
frac{partial {mathcal E}}{partial g} &= 2PBig(Y^TFB^Totimes L+BF^TYotimes L^TBig)P^Tg cr
}$$
Finding the Hessian is not worth the additional effort. Just use a gradient-based method,
e.g. Polak-Ribiere, Barzilai-Borwein, etc.
answered Jan 8 at 23:24
greggreg
7,6201821
7,6201821
$begingroup$
Thanks. I actually already had the gradient, but your derivation is very nice. I am interested in $df/dg$ in the hopes of doing Gauss-Newton (currently gradient-based methods I've tried are quite slow).
$endgroup$
– Alec Jacobson
Jan 9 at 3:07
1
$begingroup$
@AlecJacobson The gradient of a matrix wrt a vector is a 3rd order tensor. But by flattening the matrix into a vector, i.e. $,f_{vec}={rm vec}(F),,$ the gradient can be written as a matrix $$ frac{partial f_{vec}}{partial g} = (B^TG^TL^Totimes Y)KP^T + (B^Totimes YG^TL)P^T $$ where $K$ is the Commutation Matrix associated with the Kronecker product.
$endgroup$
– greg
Jan 9 at 6:21
$begingroup$
Thanks, again. Should this expression be multiplied by $g$ on the right?
$endgroup$
– Alec Jacobson
Jan 9 at 7:22
1
$begingroup$
@AlecJacobson No, the gradient is a matrix, not a vector.
$endgroup$
– greg
Jan 9 at 8:47
$begingroup$
Right. I confused myself. f is linear in g, thus the $d f /d g$ is a constant matrix.
$endgroup$
– Alec Jacobson
Jan 9 at 15:52
add a comment |
$begingroup$
Thanks. I actually already had the gradient, but your derivation is very nice. I am interested in $df/dg$ in the hopes of doing Gauss-Newton (currently gradient-based methods I've tried are quite slow).
$endgroup$
– Alec Jacobson
Jan 9 at 3:07
1
$begingroup$
@AlecJacobson The gradient of a matrix wrt a vector is a 3rd order tensor. But by flattening the matrix into a vector, i.e. $,f_{vec}={rm vec}(F),,$ the gradient can be written as a matrix $$ frac{partial f_{vec}}{partial g} = (B^TG^TL^Totimes Y)KP^T + (B^Totimes YG^TL)P^T $$ where $K$ is the Commutation Matrix associated with the Kronecker product.
$endgroup$
– greg
Jan 9 at 6:21
$begingroup$
Thanks, again. Should this expression be multiplied by $g$ on the right?
$endgroup$
– Alec Jacobson
Jan 9 at 7:22
1
$begingroup$
@AlecJacobson No, the gradient is a matrix, not a vector.
$endgroup$
– greg
Jan 9 at 8:47
$begingroup$
Right. I confused myself. f is linear in g, thus the $d f /d g$ is a constant matrix.
$endgroup$
– Alec Jacobson
Jan 9 at 15:52
$begingroup$
Thanks. I actually already had the gradient, but your derivation is very nice. I am interested in $df/dg$ in the hopes of doing Gauss-Newton (currently gradient-based methods I've tried are quite slow).
$endgroup$
– Alec Jacobson
Jan 9 at 3:07
$begingroup$
Thanks. I actually already had the gradient, but your derivation is very nice. I am interested in $df/dg$ in the hopes of doing Gauss-Newton (currently gradient-based methods I've tried are quite slow).
$endgroup$
– Alec Jacobson
Jan 9 at 3:07
1
1
$begingroup$
@AlecJacobson The gradient of a matrix wrt a vector is a 3rd order tensor. But by flattening the matrix into a vector, i.e. $,f_{vec}={rm vec}(F),,$ the gradient can be written as a matrix $$ frac{partial f_{vec}}{partial g} = (B^TG^TL^Totimes Y)KP^T + (B^Totimes YG^TL)P^T $$ where $K$ is the Commutation Matrix associated with the Kronecker product.
$endgroup$
– greg
Jan 9 at 6:21
$begingroup$
@AlecJacobson The gradient of a matrix wrt a vector is a 3rd order tensor. But by flattening the matrix into a vector, i.e. $,f_{vec}={rm vec}(F),,$ the gradient can be written as a matrix $$ frac{partial f_{vec}}{partial g} = (B^TG^TL^Totimes Y)KP^T + (B^Totimes YG^TL)P^T $$ where $K$ is the Commutation Matrix associated with the Kronecker product.
$endgroup$
– greg
Jan 9 at 6:21
$begingroup$
Thanks, again. Should this expression be multiplied by $g$ on the right?
$endgroup$
– Alec Jacobson
Jan 9 at 7:22
$begingroup$
Thanks, again. Should this expression be multiplied by $g$ on the right?
$endgroup$
– Alec Jacobson
Jan 9 at 7:22
1
1
$begingroup$
@AlecJacobson No, the gradient is a matrix, not a vector.
$endgroup$
– greg
Jan 9 at 8:47
$begingroup$
@AlecJacobson No, the gradient is a matrix, not a vector.
$endgroup$
– greg
Jan 9 at 8:47
$begingroup$
Right. I confused myself. f is linear in g, thus the $d f /d g$ is a constant matrix.
$endgroup$
– Alec Jacobson
Jan 9 at 15:52
$begingroup$
Right. I confused myself. f is linear in g, thus the $d f /d g$ is a constant matrix.
$endgroup$
– Alec Jacobson
Jan 9 at 15:52
add a comment |
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3065413%2fhow-to-optimize-a-non-linear-least-squares-energy-with-respect-to-the-non-zeros%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Are you seeking $frac{partial E(G)}{partial G}$ or $frac{partial f(G)}{partial G}$, where $E(G)$ is a scalar and $f(G)$ is a matrix? If you are looking for $frac{partial f(G)}{partial G}$, then it will be 4th order tensor (and don't think it is really needed for the optimization). I think $frac{partial E(G)}{partial G}$ should suffice your need...
$endgroup$
– user550103
Jan 8 at 5:44
$begingroup$
I'm interested in $d f(G(g))/d g$
$endgroup$
– Alec Jacobson
Jan 8 at 18:20