Derivative chain rule - Computational Science Stack Exchange most recent 30 from scicomp.stackexchange.com 2022-01-27T02:52:07Z https://scicomp.stackexchange.com/feeds/question/27236 https://creativecommons.org/licenses/by-sa/4.0/rdf https://scicomp.stackexchange.com/q/27236 0 Derivative chain rule Khue https://scicomp.stackexchange.com/users/7695 2017-06-25T20:57:31Z 2018-09-21T02:01:48Z <p>Define a sequence $(\mathbf{y})_{i=0}^N$ in $\mathbb{R}^n$ such that: $$\mathbf{y}_{k+1} = \mathbf{y}_{k} + \lambda \nabla_\mathbf{y} E(\mathbf{y}_k,\mathbf{w}), \quad k=0,1,\ldots,N-1,$$ where $\lambda$ is a constant, $\mathbf{w}\in\mathbb{R}^m$, and $E:\mathbb{R}^{n+m}\to \mathbb{R}$ is some differentiable function.</p> <p>Let $Q:\mathbb{R}^{n}\to \mathbb{R}$ be a differentiable function and $L=Q(\mathbf{y} _N)$. </p> <p>Applying the chain rule we have: $$\frac{dL}{d\mathbf{w}} = \sum_{k=1}^N\frac{\partial \mathbf{y}_k}{\partial \mathbf{w}} \frac{dQ}{d\mathbf{y}_k}\qquad (1)$$ and $$\frac{dQ}{d\mathbf{y}_k} = \frac{\partial \mathbf{y}_{k+1}}{\partial \mathbf{y}_{k}} \frac{dQ}{d\mathbf{y}_{k+1}}.\qquad (2)$$</p> <p>(Source: <a href="http://proceedings.mlr.press/v22/domke12/domke12.pdf" rel="nofollow noreferrer">this paper</a>, equation (12) and the one between (12) and (13).)</p> <p><strong>My questions:</strong> how to obtain $(1)$ and $(2)$?</p> <p>I can show that if $(2)$ holds then $(1)$ holds. But I cannot see why $(2)$ holds. Consider $k=N-1$ for example: </p> <p>Applying <a href="https://math.stackexchange.com/questions/1566376/derivation-of-the-multivariate-chain-rule/1567200#1567200">the chain rule</a> we have: \begin{align}\frac{dQ}{d\mathbf{y}_{N-1}} &amp;= \frac{dQ(\mathbf{y}_{N}(\mathbf{w},\mathbf{y}_{N-1}))}{d\mathbf{y}_{N-1}} \\ &amp;= \frac{d\mathbf{y}_{N}(\mathbf{w},\mathbf{y}_{N-1})}{d\mathbf{y}_{N-1}}\frac{dQ}{d\mathbf{y}_{N}} \\ &amp;= \begin{bmatrix}\frac{d\mathbf{w}}{d\mathbf{y}_{N-1}} &amp; \mathbf{I}\end{bmatrix}\begin{bmatrix}\frac{\partial \mathbf{y}_{N}}{\partial \mathbf{w}} \\ \frac{\partial \mathbf{y}_{N}}{\partial \mathbf{y}_{N-1}}\end{bmatrix}\frac{dQ}{d\mathbf{y}_{N}} \\ &amp;= \frac{d\mathbf{w}}{d\mathbf{y}_{N-1}}\frac{\partial \mathbf{y}_{N}}{\partial \mathbf{w}}\frac{dQ}{d\mathbf{y}_{N}} + \frac{\partial \mathbf{y}_{N}}{\partial \mathbf{y}_{N-1}}\frac{dQ}{d\mathbf{y}_{N}}, \end{align} which has an extra term $\frac{d\mathbf{w}}{d\mathbf{y}_{N-1}}\frac{\partial \mathbf{y}_{N}}{\partial \mathbf{w}}\frac{dQ}{d\mathbf{y}_{N}}$ compared to $(2)$.</p> <p>Thank you in advance for your help.</p> https://scicomp.stackexchange.com/questions/27236/-/27241#27241 1 Answer by HBR for Derivative chain rule HBR https://scicomp.stackexchange.com/users/22590 2017-06-26T19:27:25Z 2017-06-27T18:20:47Z <p>The idea is that each $\vec{y}_k$ depends on $\vec{w}$. Therefore for the first equation, simply apply the chain rule for each $\vec{y}_k$ and sum them up. Componentwise one has: $$\left(\frac{dL}{d\vec{w}}\right)_{i}=\sum_{k,\alpha}{\left(\frac{dQ}{d\vec{y}_k}\right)_{\alpha}\left(\frac{\partial \vec{y}_k}{\partial \vec{w}}\right)_{i\alpha}} \tag{*}$$ Maybe the order in which they appear multiplying each other has confused you.</p> <p>The second is obtained supposing that the function $\vec{y}_{k}$ can be put as a function of $\vec{y}_{k+1}$ (your first equation suggets this). Therefore the derivative in $(*)$ can be expressed as: $$\frac{dQ}{d\vec{y}_k}=\frac{\partial \vec{y}_{k+1}}{\partial \vec{y}_k}\frac{dQ}{d\vec{y}_{k+1}}$$</p>