0
$\begingroup$

Definitions

  1. Consider the following function $f:\mathbb{R}^N\mapsto\mathbb{R^2}$ \begin{equation*}f(\ell_{k+1})= \left[\begin{array}{c} v_{k+1}\,\cos(h_{k+1})\\ v_{k+1}\,\sin(h_{k+1}) \end{array}\right]= v_{k+1}\left[\begin{array}{c} \cos(h_{k+1})\\ \sin(h_{k+1}) \end{array}\right]\end{equation*} where $h_{k+1}$ and $v_{k+1}$ are respectively the first and second component of the column vector $\ell_{k+1}$ living in $\mathbb{R}^N$, i.e. \begin{equation*}\ell_{k+1}=\left[\begin{array}{ccc} h_{k+1} & v_{k+1} & \tilde{\ell}_k'\end{array}\right]'\end{equation*} here $'$ is the transposition operator and $\tilde{\ell}_{k+1}$ is a column vector containing $N-2$ variables that are not relevant in the actual problem. Consequently, the function $f$ can be expressed as \begin{equation*}f(\ell_{k+1})=(C_v \ell_{k+1})\left[\begin{array}{c} \cos(C_h \ell_{k+1})\\ \sin(C_h \ell_{k+1}) \end{array}\right]\end{equation*} if $C_{v}$, $C_{h}$ are defined as \begin{equation*}C_v \triangleq \left[\begin{array}{ccc} 0 & 1 & 0_{1\times (N-2)}\end{array}\right] \qquad C_h \triangleq \left[\begin{array}{ccc} 1 & 0_{1\times (N-1)}\end{array}\right] \end{equation*} and $0_{a\times b}$ denotes a $a\times b$ matrix full of zeros.

  2. The vector $\ell_{k+1}$ is computed according to the linear equation \begin{equation*}\ell_{k+1}=F_{\ell}\,\ell_k+G_{\ell}\,u_k\end{equation*} where $F_{\ell}$, $G_{\ell}$ are two given matrices whose entries are constants and $\ell_k$, $u_k$ are vectors representing the independent variables of the problem. Now, plugging the equation for $\ell_{k+1}$ in $f$ gives the final expression \begin{equation*}f(\ell_k,u_k)=[C_v (F_{\ell}\ell_k+G_{\ell}u_k)]\left[\begin{array}{c} \cos[C_h (F_{\ell}\ell_k+G_{\ell}u_k)]\\ \sin[C_h (F_{\ell}\ell_k+G_{\ell}u_k)] \end{array}\right]\end{equation*}


Problem

I want to find the explicit expressions of the two Jacobians \begin{equation*} J^{\ell}\triangleq \frac{\partial f}{\partial \ell_k} \qquad J^{u}\triangleq \frac{\partial f}{\partial u_k} \end{equation*} but, due to the quite involved notations, I'm experiencing some difficulties in their computations. I believe that is easier to work with the representation \begin{equation*}f(\ell_k,u_k)=v_{k+1}\left[\begin{array}{c} \cos(h_{k+1})\\ \sin(h_{k+1}) \end{array}\right]\end{equation*} and keeping in mind that $v_{k+1}$, $h_{k+1}$ depends on $\ell_k$, $u_k$ via the relations \begin{equation*}\begin{aligned} v_{k+1}&=C_{v}(F_{\ell}\ell_k+G_{\ell}u_k)\\ h_{k+1}&=C_{h}(F_{\ell}\ell_k+G_{\ell}u_k)\\ \end{aligned}\end{equation*}


First Jacobian

Due to the product rule, for the Jacobian in $\ell_k$ holds \begin{equation*}\begin{aligned} \frac{\partial f}{\partial \ell_k}&=\left[\begin{array}{c} \cos(h_{k+1})\\ \sin(h_{k+1}) \end{array}\right]\left\{\frac{\partial v_{k+1}}{\partial \ell_k}\right\}+v_{k+1}\left\{\frac{\partial}{\partial \ell_k}\left[\begin{array}{c} \cos(h_{k+1})\\ \sin(h_{k+1}) \end{array}\right]\right\}\\ \end{aligned}\end{equation*}

and for the chain rule

\begin{equation*}\begin{aligned} \frac{\partial f}{\partial \ell_k}&=\left[\begin{array}{c} \cos(h_{k+1})\\ \sin(h_{k+1}) \end{array}\right]\left\{\frac{\partial v_{k+1}}{\partial \ell_k}\right\}+v_{k+1}\left[\begin{array}{c} -\sin(h_{k+1})\\ \cos(h_{k+1}) \end{array}\right]\left\{\frac{\partial h_{k+1}}{\partial \ell_k}\right\}\\ \end{aligned}\end{equation*} Note that I've deliberately written the gradients $\partial v_{k+1}/\partial \ell_k$, $\partial h_{k+1}/\partial \ell_k$ on the RHS of the vectors $[\cos(h_{k+1}), \sin(h_{k+1})]'$, $[-\sin(h_{k+1}), \cos(h_{k+1})]'$ in order to maintain dimension-consistent the products involved.

Now, taking into account the relations defining $v_{k+1}$, $h_{k+1}$, \begin{equation*} \frac{\partial v_{k+1}}{\partial \ell_k}=C_{v}F_{\ell} \qquad \frac{\partial h_{k+1}}{\partial \ell_k}=C_{h}F_{\ell} \end{equation*} so my conclusion is \begin{equation*}\begin{aligned} \frac{\partial f}{\partial \ell_k}&=\left[\begin{array}{c} \cos(h_{k+1})\\ \sin(h_{k+1}) \end{array}\right]\odot(C_v F_{\ell})+v_{k+1}\left[\begin{array}{c} -\sin(h_{k+1})\\ \cos(h_{k+1}) \end{array}\right]\odot(C_h F_{\ell})\\ \end{aligned}\end{equation*} where, once again in order to maintain consistent the dimensions, $\odot$ denotes the element-wise product.


Second Jacobian

Following the same derivation, it turns out that the second Jacobian is given by

\begin{equation*}\begin{aligned} \frac{\partial f}{\partial u_k}&=\left[\begin{array}{c} \cos(h_{k+1})\\ \sin(h_{k+1}) \end{array}\right]\odot(C_v G_{\ell})+v_{k+1}\left[\begin{array}{c} -\sin(h_{k+1})\\ \cos(h_{k+1}) \end{array}\right]\odot(C_h G_{\ell})\\ \end{aligned}\end{equation*}


Question

As you can see, I'm quite confused with the dimension of the factors involved in the various multiplication. I've tried to adjust the formulas in order to get feasible the computation of linear approximation \begin{equation*}\tilde{f}(\ell_{k}, u_k)\triangleq J^{\ell} \ell_k+J^{u} u_k\end{equation*} of the given function $f$. However, I believe that I've just made only a big mess.

My questions are the following:

1) My results are correct?

2) Is there a more clear way to compute the Jacobians?

$\endgroup$

1 Answer 1

1
$\begingroup$

$ \def\bbR#1{{\mathbb R}^{#1}} \def\a{\alpha}\def\b{\beta}\def\g{\gamma}\def\t{\theta} \def\l{\lambda}\def\s{\sigma}\def\e{\varepsilon} \def\o{{\tt1}}\def\p{\partial} \def\L{\left}\def\R{\right}\def\LR#1{\L(#1\R)} \def\trace#1{\operatorname{Tr}\LR{#1}} \def\qiq{\quad\implies\quad} \def\grad#1#2{\frac{\p #1}{\p #2}} \def\c#1{\color{red}{#1}} \def\m#1{\left[\begin{array}{r}#1\end{array}\right]} $For ease of typing, I'll rename some of your variables $$\eqalign{ \LR{\ell_k,\ell_{k+1},C_h,C_v,F_\ell,G_\ell,N} \to \LR{x,w,e_1,e_2,F,G,n} \\ }$$ where $\{e_j\in\bbR{n}\}$ denote the standard basis vectors.

The following matrix will also be useful $$\eqalign{ K &= \m{0&-\o\\ \o&0} \qiq K\m{a_1\\a_2} = \m{-a_2\\a_1} \\ }$$ Now calculate the gradient of the function $$\eqalign{ f &= f(w) = \LR{e_2^Tw}\,\m{\cos(e_1^Tw)\\ \sin(e_1^Tw)} \\ df &= \m{\cos(e_1^Tw)\\ \sin(e_1^Tw)}\LR{e_2^Tdw} + \LR{e_2^Tw}\,\m{-\sin(e_1^Tw)\\ \cos(e_1^Tw)}\LR{e_1^Tdw} \\ &= \LR{\frac{f}{e_2^Tw}}\LR{e_2^Tdw} + Kf\,{e_1^Tdw} \\ \grad{f}{w} &= \LR{\frac{fe_2^T}{e_2^Tw}} + Kf{e_1^T} \\ }$$ The gradients of $w$ wrt $x$ and $u$ are trivial computations. $$\eqalign{ w &= Fx + Gu \quad\qiq F=\grad{w}{x},\;G=\grad{w}{u} \\ }$$ The chain rule yields the desired gradients. $$\eqalign{ \grad{f}{x} &= \grad{f}{w}\cdot\grad{w}{x} \qquad\qquad \grad{f}{u} &= \grad{f}{w}\cdot\grad{w}{u} \\ }$$

$\endgroup$
2
  • $\begingroup$ Thank you greg, it seems that your conclusions are the same as mine $\endgroup$
    – matteogost
    Commented Feb 20, 2022 at 20:37
  • $\begingroup$ @matteogost Except that my gradients do not use element-wise products. $\endgroup$
    – greg
    Commented Feb 21, 2022 at 13:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .