A partial derivative measures how a function’s output changes concerning one of its input variables while holding all other variables constant. Mathematically, the partial derivative of a function $f$ with respect to a variable $x_i$ is denoted as:
$$
\frac{\partial f}{\partial x_i}
$$
Let’s consider an example:
Suppose we have a function $f(x, y) = x^2 + 3xy – 2y^2$. We want to find $\frac{\partial f}{\partial x}$ and $\frac{\partial f}{\partial y}$.
Mixed partial derivatives involve taking partial derivatives of a function with respect to one variable and then with respect to another variable. It doesn’t matter in which order you take these derivatives. The notation for mixed partial derivatives is denoted as follows:
$$
\frac{\partial^2 f}{\partial x \partial y} \quad \text{and} \quad \frac{\partial^2 f}{\partial y \partial x}
$$
Let’s continue with our previous function $f(x, y) = x^2 + 3xy – 2y^2$. Now, we want to find $\frac{\partial^2 f}{\partial x \partial y}$ and $\frac{\partial^2 f}{\partial y \partial x}$.
In both cases, we obtained the same result, which is 3.
To compute partial derivatives in Python, you can use libraries like SymPy or scipy. Here’s an example using SymPy:
import sympy as sp
x, y = sp.symbols('x y')
f = x**2 + 3*x*y - 2*y**2
# Partial derivative with respect to x
df_dx = sp.diff(f, x)
# Partial derivative with respect to y
df_dy = sp.diff(f, y)
print("Partial derivative with respect to x:", df_dx)
print("Partial derivative with respect to y:", df_dy)In deep learning, partial derivatives are prominently used in optimization algorithms, such as gradient descent and back-propagation. These algorithms rely on computing gradients, which are essentially vectors of partial derivatives. Gradients guide the model’s parameter updates, making partial derivatives a critical concept for training neural networks efficiently.
By understanding partial derivatives and their role in optimization, you can gain insights into how deep learning models learn and improve their performance during training.