Most of the neural network models in contemporary deep learning packages are trained based on gradients.
Let $f: \mathbb{R}^m \rightarrow \mathbb{R}^n$ be a function for which we want to find a gradient, then the gradient is generally represented by a Jacobian matrix that looks like below
$$J = \begin{bmatrix} \dfrac{\partial y_1}{\partial x_1} & \dfrac{\partial y_1}{\partial x_2} & \dfrac{\partial y_1}{\partial x_3} &\dots & \dfrac{\partial y_1}{\partial x_m} \\ \dfrac{\partial y_2}{\partial x_1} & \dfrac{\partial y_2}{\partial x_2} & \dfrac{\partial y_2}{\partial x_3} &\dots & \dfrac{\partial y_2}{\partial x_m} \\ \cdots & \cdots & \cdots & \cdots & \cdots \\ \dfrac{\partial y_n}{\partial x_1} & \dfrac{\partial y_n}{\partial x_2} & \dfrac{\partial y_n}{\partial x_3} &\dots & \dfrac{\partial y_n}{\partial x_m} \\ \end{bmatrix} $$
For example: If $f(x_1, x_2) = \begin{bmatrix} x_1 + x_2 \\ x_1x_2 \end{bmatrix}$ then $J = \begin{bmatrix} 1 & 1 \\ x_2 & x_1 \end{bmatrix}$
After calculating the Jacobian matrix, we can substitute the co-ordinate values of a particular point so that we can obtain a real matrix which is a gradient at a particular point.
$$ J_{(4, 5)} = \begin{bmatrix} 1 & 1 \\ 5 & 4 \end{bmatrix} $$
In order to perform the gradient of a function at a point, the algorithm I know is as follows:
- Write each output of the function in the analytical form in terms of input;
- Apply partial derivative on each output w.r.t each input;
- Substitute the values of the input point at which we want to find the gradient.
Thus, finally, we will get the gradient.
Do the popular packages like PyTorch, Tensorflow, Keras, etc., use this or a variant of this algorithm to find the gradients at a particular point?
If yes, will those packages be able to write the analytical forms of all the output variables in terms of input variables?
If not, what is the high-level algorithm for calculating gradients? Is it based on geometrical slope version of gradient?