Lensa ML
Lensa ML

Partial Derivatives & Gradients

Step 1 of 6

From 1D to 2D

Single derivatives become partial derivatives in multiple dimensions

Blend: 1D → 2D0.00
f(x) = x²x12468f(x,y) = x² + y²xy
DIMENSIONS
1D
VARIABLES
x
DERIVATIVE
df/dx

In 1D, f(x) = x² has one derivative: df/dx = 2x. There's only one direction to change, so one slope tells the whole story.

Step 1 of 6: From 1D to 2D

Single derivatives become partial derivatives in multiple dimensions

Blend: 1D → 2D0.00
f(x) = x²x12468f(x,y) = x² + y²xy
DIMENSIONS
1D
VARIABLES
x
DERIVATIVE
df/dx

In 1D, f(x) = x² has one derivative: df/dx = 2x. There's only one direction to change, so one slope tells the whole story.

Step 2 of 6: Partial Derivative Notation

Hold one variable fixed, differentiate the other

x value1.50
Slice: f(x, y=1) = x² + x·1 + 1²x
f(x,y)
4.75
∂f/∂x
4.00
x
1.50
y (FIXED)
1.0

∂f/∂x = 4.00 — the function is increasing in x at this point. The teal tangent line tilts upward. We hold y = 1 fixed and only vary x.

Step 3 of 6: The Gradient Vector

Combine all partial derivatives into one vector: ∇f

x position1.50
y position1.00
∇f = (∂f/∂x, ∂f/∂y) = (2x, 2y)∇f
∂f/∂x
3.00
∂f/∂y
2.00
|∇f|
3.61
f(x,y)
3.25

Strong gradient! Far from the minimum, the surface is steep. The gradient arrow grows because the bowl gets steeper as you move outward.

Step 4 of 6: Gradient Direction & Magnitude

The gradient points uphill with magnitude equal to the steepness

x position1.00
y position1.50
f(x,y) = sin(x)·cos(y)
|∇f|
0.840
ANGLE (°)
-87.4
f(x,y)
0.060

Strong gradient (|∇f| = 0.84) pointing at -87°. The surface is steep here. Moving opposite to this direction is the fastest way downhill — that's gradient descent.

Step 5 of 6: Gradient Descent Connection

Step opposite to ∇f to minimize the loss

Learning rate0.15
Step0
f(x,y) = x² + 3y²min
STEP
0
f(x,y)
18.250
x
2.500
y
2.000

Starting point (2.5, 2.0) — far from the minimum. The teal arrow shows −∇f, the direction gradient descent will step. Increase the step slider to descend.

Step 6 of 6: Higher Dimensions

The same idea scales to millions of parameters

Number of dimensions2
2x14x2∇f = (2, 4)Each bar = ∂f/∂xᵢ at point (1,1,...,1)
DIMENSIONS
2
|∇f|
4.47
PARAMS
2
MAX ∂f/∂xᵢ
4

In 2D, the gradient is a vector with 2 components — one partial derivative per variable. We can still visualize this. In ML, the concept is identical, just with more dimensions.