Suppose I have a two vector-valued functions $F$ and $G$:
$$ F(\boldsymbol{\rho}) = \big(\ f_{1}(\boldsymbol{\rho}), \cdots ,f_{n}(\boldsymbol{\rho})\ \big)\\ G(\boldsymbol{\rho}) = \big(\ g_{1}(\boldsymbol{\rho}), \cdots ,g_{n}(\boldsymbol{\rho})\ \big) $$
where $\boldsymbol{\rho}$ is in $\mathbb{R}^3$ and $F$ and $G$ map $\mathbb{R}^3 \rightarrow \mathbb{R}^n$. Now I have a third vector-valued function $H$ that takes output of $F$ and $G$ such that:
$$ H(F(\boldsymbol{\rho}), G(\boldsymbol{\rho})) = \bigg(\ h_{1}\big(f_{1}(\boldsymbol{\rho}), g_{1}(\boldsymbol{\rho})\big), \cdots, h_{n}\big(f_n(\boldsymbol{\rho}), g_{n}(\boldsymbol{\rho})\big) \ \bigg) $$
The function $H$ takes two vectors in $\mathbb{R}^n$ and gives a $\mathbb{R}^n$ vector as result. I'm not sure if the above notation is actually valid... I want to calculate the Jacobian of $H$ w.r.t $\boldsymbol{\rho}$. Is there a way to decompose the Jacobian into the partial derivatives of $F, G$ and $H$ using the chain-rule?
I am able to calculate the gradient of $h_i$ w.r.t. $\boldsymbol{\rho}$ seperately:
$$ \nabla h_i (\boldsymbol{\rho}) = \bigg[\frac{\partial{h_i}}{\partial{\rho_1}}, \frac{\partial{h_i}}{\partial{\rho_2}}, \frac{\partial{h_i}}{\partial{\rho_3}} \bigg] \\ = \bigg[\frac{\partial{h_i}}{\partial{f_i}} \frac{\partial{f_i}}{\partial{\rho_1}} + \frac{\partial{h_i}}{\partial{g_i}} \frac{\partial{g_i}}{\partial{\rho_1}}, \cdots, \frac{\partial{h_i}}{\partial{f_i}} \frac{\partial{f_i}}{\partial{\rho_3}} + \frac{\partial{h_i}}{\partial{g_i}} \frac{\partial{g_i}}{\partial{\rho_3}} \bigg] \\ = \begin{bmatrix}\frac{\partial{h_i}}{\partial{f_i}} & \frac{\partial{h_i}}{\partial{g_i}}\end{bmatrix} \begin{bmatrix} \frac{\partial{f_i}}{\partial{\rho_1}} & \frac{\partial{f_i}}{\partial{\rho_2}} & \frac{\partial{f_i}}{\partial{\rho_3}} \\ \frac{\partial{g_i}}{\partial{\rho_1}} & \frac{\partial{g_i}}{\partial{\rho_2}} & \frac{\partial{g_i}}{\partial{\rho_3}}\end{bmatrix} $$
and the Jacobian that I'm after:
$$ J(H) = \begin{bmatrix} \nabla h_1 (\boldsymbol{\rho}) \\ \vdots \\ \nabla h_n (\boldsymbol{\rho})\end{bmatrix} $$
But is there a way to vectorize the whole process (in python) and calculate the Jacobian in one go without using a loop to calculate all $n$ gradients seperately? I'm not sure if it makes a differences but functions in $F$ are related by a constant, $c_i$, and so are the functions in $G$ such that:
$$ f_i(\boldsymbol{\rho}) = c^1_i\ m(\boldsymbol{\rho}) \\ g_i(\boldsymbol{\rho}) = c^2_i\ n(\boldsymbol{\rho}) $$
where $c_i$ is:
$c^1 = \begin{bmatrix} c^1_1 \\ \vdots \\ c^1_n\end{bmatrix}$ and $c^2 = \begin{bmatrix} c^2_1 \\ \vdots \\ c^2_n\end{bmatrix}$ and $m$ and $n$ are functions that map $\mathbb{R}^3 \rightarrow \mathbb{R}^1$