1.2.8 · D1Calculus & Optimization Basics

Foundations — Convex vs non-convex functions

2,098 words10 min readBack to topic

This page assumes you know nothing. Every squiggle the parent note used — , , , , , — is built here from the ground up, one at a time, each with a picture and a reason it exists. Read top to bottom; nothing is used before it's earned.


0. What is a function , really?

The picture of a function is its graph: for every input on the horizontal axis, we plot a point at height . Sweep across all inputs and the dots join into a curve.

Figure — Convex vs non-convex functions

Why the topic needs it: in machine learning the machine is a loss function Loss Functions — you feed it your model's settings, it tells you how wrong the model is. The whole topic is about the shape of that curve.


1. The parameter symbol

So = "how bad is the model when the knobs are set to ." Turning the knobs moves you left/right along the floor; the loss curve tells you the height there. Optimization = find the knob setting with the lowest height.

Why the topic needs it: the parent note's sentence "minimize " is meaningless until you know is just the input to a function-machine.


2. Two points and the segment between them

To even state convexity we must talk about "any two points" and "the line between them." So we need a clean way to name every point on that connecting line using one slider.

Given two floor-positions and , the blended position is

Read it as a recipe: take scoops of and scoops of .

  • : all → you're standing at .
  • : all → you're standing at .
  • : half-and-half → the exact midpoint.

As slides from to , the blended point sweeps the entire straight segment between and . One dial, every in-between point.

Figure — Convex vs non-convex functions

Why the topic needs it: this exact expression appears on both sides of the master convexity inequality. Left side blends the inputs; right side blends the outputs.


3. The chord vs the curve

Take the two graph points and . The straight line joining them is the chord.

Convex means: curve height chord height, for every choice of . That's it — the parent's "master definition" decoded.

Figure — Convex vs non-convex functions

4. Slope, then the derivative

To talk about tangent lines (Lens 2) and curvature (Lens 3), we need slope.

Why this tool and not another? We ask "which way is downhill, and how steep?" — that is a question about instantaneous slope, and the derivative is the one tool that answers it. Averages over an interval won't do; we need the slope at a single knob-setting so we know which way to nudge.

A point where is flat — a stationary point. Bottoms of valleys, tops of hills, and saddle flat-spots all have zero slope. (Which kind it is comes next.)


5. Second derivative — the curvature

Slope tells you the tilt. But convexity is about whether the curve bends up or down. So we take the slope of the slope.

Figure — Convex vs non-convex functions

Why this is THE practical convexity test: "does the curve cup upward everywhere?" is exactly " everywhere." One clean sign-check, no dragging chords around. This is the parent's Lens 3 in 1D. See Taylor Series Expansion for why is precisely the coefficient of curvature in the local picture.


6. Going multivariate: the gradient and the transpose

Real models have many knobs, so is a list of numbers (a vector), and eats the whole list.

So the first-order condition reads: the number is just "slope how far you moved," i.e. the height the flat tangent predicts.

Why the topic needs it: with many knobs you can't say "left/right"; the gradient packages all directions, and is the glue that turns a direction-of-motion into a predicted height change.


7. The Hessian and ""

Curvature in many dimensions isn't a single number — a surface can cup up one way and dome down another (a saddle!). We need a table of curvatures.

Figure — Convex vs non-convex functions

Why the topic needs it: multivariate convex everywhere. One downward-bending direction (one negative slice) and you get a saddle — non-convex — and the guarantee that local = global evaporates.


8. Putting the payoff in one line

Convex bowl ⇒ a flat spot () can only be the bottom ⇒ every local minimum is the global minimum. That single implication is why Convex Optimization is "easy" and neural nets are "hard."


Prerequisite map

Function f and its graph

Parameter theta = the knobs

Slope and derivative f prime

Blend lambda x plus one minus lambda y

Chord vs curve inequality

Second derivative f double prime = curvature

1D convex test f double prime not below zero

Gradient nabla f and transpose

Hessian nabla squared f

Positive semidefinite test PSD

Convex vs non-convex

Local min equals global min payoff


Equipment checklist

Reveal each and check you could explain it cold.

What does mean and what is its picture?
A machine turning input into one output height ; its picture is the graph — a curve of heights over the input axis.
What is and why not just call it ?
The model's adjustable knobs (weights); we rename it to flag "these are the things we tune."
What does do in ?
It's a mixing dial sweeping every point on the straight segment from (at ) to (at ).
Curve height vs chord height at a blended point?
Curve = (blend inputs, then apply ); chord = (blend the two heights).
State convexity in words.
The curve stays on or below every chord — a single upward bowl.
What is and why do we need it?
The instantaneous slope at ; it answers "which way is downhill and how steep," which gradient descent needs.
What does everywhere tell you?
The curve cups upward everywhere ⇒ it's convex (1D test).
What is ?
The list of slopes across all input directions — an arrow pointing steepest uphill (multi-knob ).
What does compute?
The dot product: multiply matching entries, add them — a single number for how aligned two arrows are.
What is the Hessian ?
The grid of all second derivatives — curvature in and between every direction (multi-knob ).
What does (PSD) mean geometrically?
For every direction , — the surface never bends downward along any slice.
The one payoff of convexity?
Every local minimum is automatically the global minimum.
Recall Feynman check

Explain to a 12-year-old: a function is a candy machine (input coin position → output height). Convex means the machine's height-graph is one smooth soup bowl. Stretch a string between any two spots on the bowl — the string is always above the bowl, never cutting through it. That's why a dropped marble always finds the one true bottom.