Forward Differentiation and Inverse Automatic Differentiation Computation of Composite Functions
with respect to
- First published: 2024-09-13
- Reference:
- /2016-12-30/reverse-mode-automatic-differentiation
- Calculus Early Transcendentals 9e - James Stewart (2020)
- /wiki/Automatic_differentiation
- Please do not hesitate to point out any mistakes.
Forward and backward automatic differentiation: mathematics
Let's review the calculus derivation rules first
Calculus Derivative Laws Review
multiplication rule
division rule
Derivation of cos and sin
Chain rule (univariate composite function)
Multivariate chain rule (Case 1)
Multivariate chain rule (Case 2)
When calculating\(\frac{\partial z}{\partial s}\)When we hold\(t\) Fixed and calculated\(z\) treat (sb a certain way)\(s\) of ordinary derivatives, i.e., applying the multivariate chain rule (Case 1). Calculating the\(\frac{\partial z}{\partial t}\)The same reasoning applies at the time.
Multivariate chain rule (generalized version)
Composite functions, partial differentiation, chain rule, forward and backward automatic differentiation
Order of calculation of forward and reverse
For combinatorial functions:
The chain rule will be given:
Calculation order:
- The forward differentiation is calculated by first calculating\(\partial w_1 / \partial x\)Then calculate\(\partial w_2/\partial w_1\)Final calculations\(\partial y / \partial w_2\)
- The backward differentiation is calculated by first calculating\(\partial y / \partial w_2\)Then calculate\(\partial w_2/\partial w_1\)Final calculations\(\partial w_1 / \partial x\)
(math.) forward differentiation
For combinatorial functions:
Forward differential calculus:
(coll.) fail (a student)\(v=r\)upcoming\(r\)as an independent variable and set\(s\)cap (a poem)\(t\)When fixed, this gives
(coll.) fail (a student)\(v=s\)upcoming\(s\)as an independent variable and set\(r\)cap (a poem)\(t\)When fixed, this gives
(coll.) fail (a student)\(v=t\)upcoming\(t\)as an independent variable and set\(s\)cap (a poem)\(r\)When fixed, this gives
(math.) inverse differential
For combinatorial functions:
Reverse differential calculus:
One can imagine having a function\(s=function(y_1,y_2,y_3)\)
(coll.) fail (a student)\(s=y_1\)upcoming\(y_1\)as an independent variable and set\(y_2\)cap (a poem)\(y_3\)When fixed, this gives
Calculation of automatic differentiation by example
(for) instance
Suppose there are 2 input variables (\(x_1\), \(x_2\)) and 2 output variables (\(y_1\), \(y_2\)):
To wit:
Among them:
Next, we will illustrate how to perform forward autodifferentiation and backward autodifferentiation with this example
Forward automatic differentiation
We will use the following chain rule:
Among them:
-
\(w\)represent an output
- In the example, for the\(y_1\)or\(y_2\)
-
\(u_i\)Expressing direct impact\(w\)input variable
- In the example, for the\(a\)cap (a poem)\(b\)
-
\(t\)indicateTo be giveninput variable
- In the example, for the\(x_1\)or\(x_2\)one of them
Before calculating it, we break down Eq. (1) into simple arithmetic calculations:
Now we are interested in the variables to be given\(t\)Ask for guidance:
As mentioned earlier\(t\)is yet to be given, and now is the time to give it:
- commander-in-chief (military)\(t=x_1\)Substituting into the above equation, the\(\frac{\partial x_1}{\partial t} = 1\)(indicates contrast)\(\frac{\partial x_2}{\partial t}=0\)The following can then be computed\(\frac{\partial y_1}{\partial x_1}\)cap (a poem)\(\frac{\partial y_2}{\partial x_1}\)
- commander-in-chief (military)\(t=x_2\)Substituting into the above equation, the\(\frac{\partial x_1}{\partial t} = 0\)(indicates contrast)\(\frac{\partial x_2}{\partial t}=1\)The following can then be computed\(\frac{\partial y_1}{\partial x_2}\)cap (a poem)\(\frac{\partial y_2}{\partial x_2}\)
It can be inferred:
- just at (a time or place)\(n\)In the case of two input variables (there are two in this example), it is necessary to compute the\(n\)times the above formula.
- Assuming that the input in the neural network is a 1280 x 720 picture and the output is 51 floating point numbers, the forward differentiation method requires 921600 computations.
Reverse auto-differentiation
We will use the following chain rule:
Among them:
- \(u\) Indicates an input variable
- \(w_i\) express reliance on\(u\) output variable
- \(s\) indicateTo be givenvariable
Recall that the disassembled simple arithmetic computes (2):
Now compute the backward differential:
(coll.) fail (a student)\(s=y_1\)Hours:
Similarly one can calculate when\(s=y_2\)Hours.
It can be inferred:
- just at (a time or place)\(n\)In the case of two output variables (there are two in this example), it is necessary to compute the\(n\)times the above formula.
- Assuming that the input in the neural network is a 1280 x 720 image and the output is 51 floating point numbers, the backward differentiation method would need to be computed 51 times.