This Optimization concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.
Optimization
Convex Sets, Convex Functions, and Jensen's Inequality
Convexity is the mixture-preserving geometry that turns local checks into global optimization guarantees and underlies many ML losses and variational bounds.
Concept Structure
Convex Sets, Convex Functions, and Jensen's Inequality
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learner Contract
What this page should let you do.
3 prerequisites listed; refresh them before leaning on the math or code.
Explain the mechanism, trace the main notation, and test one prediction in the live demo.
Read the intuition before the notation; the math should name a mechanism you already felt.
Follow this edge after making one prediction here; the next page should reuse the result, not restart the route.
Claim/source review status
Substantive review recorded
1/1 claims have bounded review metadata; still check caveats and source scope.Metadata-derived; review may be AI-assisted. Not a human certification.01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
Convexity is the geometry of mixing without surprise.
Take two points and . If every mixture between them,
stays inside a set, the set has no inward bite along that chord. That is a convex set. A disk is convex. A crescent is not, because two safe points can have a line segment that leaves the crescent.
A convex function applies the same idea to height. Draw a chord between two graph points, and . If the graph between them never rises above that chord, the function is convex. The function may curve, but it curves in a disciplined way: the value at a mixed input is no larger than the same mixture of endpoint values.
That single picture explains a lot of machine-learning optimization:
- A convex loss does not hide a better valley behind a worse local basin. Local improvement is enough to reason globally.
- A nonconvex neural-network loss can still borrow local tools from convex optimization, but the guarantees change.
- Jensen's inequality is the algebraic version of the chord picture. It tells you what happens when you evaluate a convex function after averaging, rather than average after evaluating.
The main danger is overgeneralizing. Convexity is not a synonym for easy, and most deep neural-network objectives are not convex in all parameters. It is the clean reference case: when the geometry is convex, we can prove things that become only heuristics or local diagnostics in deep learning.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Let . The set is convex when for every and every ,
The vector is a weighted average of the two points. When , it is ; when , it is ; and for values in between it traces the line segment between them.
Let , where is convex. The function is convex when for every and ,
The left side evaluates the function after mixing the inputs. The right side mixes the function values. Their difference,
is the Jensen gap for this two-point mixture. Convexity says for every allowed pair and mixture weight.
Jensen's inequality extends the same idea to finitely many points. If is convex, , and weights satisfy , then
For a random variable with values in , and with the relevant expectations well-defined, the expectation version is
This is why Jensen appears in probabilistic ML. Moving a convex function outside or inside an average is not neutral; it introduces an inequality direction.
There are two extremely useful equivalent tests.
First, the epigraph of is
The function is convex exactly when is a convex set. Instead of looking at a curve and chords, you can look at the region above the graph.
Second, if is differentiable on a convex domain, then is convex exactly when every tangent plane is a global underestimator:
This is the local-to-global bridge. For a differentiable convex function, any point with satisfies
So is a global minimizer. More generally, convex functions have no non-global local minima. In a nonconvex neural-network objective, the same gradient-zero condition can describe a local minimum, saddle, or maximum; convexity is what makes the local condition globally trustworthy.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
import numpy as np
# Two functions on R: one convex, one nonconvex.
def convex_f(x): return (x - 1.0) ** 2 + 0.2 * x
def nonconvex_f(x): return np.sin(2.0 * x) + 0.15 * x ** 2
def jensen_gap(f, x, y, theta):
mix_x = theta * x + (1.0 - theta) * y
chord_value = theta * f(x) + (1.0 - theta) * f(y)
return chord_value - f(mix_x)
grid = np.linspace(-2.0, 3.0, 51)
thetas = np.linspace(0.0, 1.0, 21)
for name, f in [("convex", convex_f), ("nonconvex", nonconvex_f)]:
worst_gap = float("inf")
witness = None
for x in grid:
for y in grid:
for theta in thetas:
gap = jensen_gap(f, x, y, theta)
if gap < worst_gap:
worst_gap = gap
witness = (x, y, theta)
clean_witness = tuple(round(float(v), 3) for v in witness)
print(name, "worst Jensen gap:", round(worst_gap, 4), "at", clean_witness)
The convex quadratic should have a nonnegative worst sampled gap, up to floating-point noise. The nonconvex function should produce a negative gap for some pair: the graph rises above a chord, so the chord test fails.
This sampled check does not prove a function is convex. It is a witness machine: a negative Jensen gap proves nonconvexity for that pair, while many nonnegative samples merely increase confidence over the sampled region.
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Use the Jensen mixture lab to test the definition instead of just reading it.
In the Function chord stage, choose a function family, endpoints , and a mixture weight . Before reveal, the page shows the endpoints and chord but hides the interior function value. Commit to one prediction:
- Mixture stays safe: the local chord/Jensen test passes.
- Chord or segment breaks: the hidden interior value violates convexity for this pair.
- Domain fails first: the selected mixture is not a valid convexity test because an endpoint or mixed point is outside the domain.
On reveal, the demo draws the hidden curve/interior point and reports the Jensen gap
In the Set segment stage, choose a disk, box, annulus, or crescent and move two endpoints. Predict whether the full segment stays inside. This keeps the two ideas linked: convex functions are chord-disciplined functions on convex domains, not just curves that "look bowl-shaped."
Live Concept Demo
Explore Convex Sets, Convex Functions, and Jensen's Inequality
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Commit to what Convex Sets, Convex Functions, and Jensen's Inequality should make visible before reading the result.
After The First Pass
Turn the concept into an inspected object.
Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.
Mechanism Storyboard
See the idea move before the page explains it
Convexity is the mixture-preserving geometry that turns local checks into global optimization guarantees and underlies many ML losses and variational bounds.
Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change Convex Sets, Convex Functions, and Jensen's Inequality should make visible.
Visual Inquiry
Make the image answer a mathematical question
Convexity is the mixture-preserving geometry that turns local checks into global optimization guarantees and underlies many ML losses and variational bounds.
Which visible object should carry the first intuition?
Pick the cue that should make Convex Sets, Convex Functions, and Jensen's Inequality easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
Primary source for convex sets, convex functions, Jensen's inequality, epigraphs, first-order conditions, and global optimality in convex optimization.
Open sourceConnects convexity to machine-learning optimization, gradients, loss functions, and mathematical prerequisites.
Open sourceFrames convex optimization as a reference case for deep-learning optimization while emphasizing that neural-network objectives are usually nonconvex.
Open sourceClaim Review
Convexity is the mixture-preserving geometry that turns local checks into global optimization guarantees and underlies many ML losses and variational bounds.
Claims without a substantive review badge still need exact source-support review.
boyd-2004-convex-optimization, deisenroth-2020-mml, goodfellow-2016-deep-learning
Use equations, runnable code, and demos to check whether the source support is operational.
Boyd/Vandenberghe support convex set/function definitions, Jensen extensions, epigraph equivalence, and the differentiable global-underestimator test. MML supports the local/global minimum framing for convex ML optimization. Deep Learning Book supports convex optimization as reference case and neural-network objectives as generally nonconvex.
Sources: Convex Optimization, Mathematics for Machine Learning, Deep LearningChecks core convex-analysis and ML-framing claims only; not neural-network convexity, optimizer convergence from Jensen alone, universal convexity of useful ML losses, or GPT Pro publication approval.A bounded review summary is present; still check caveats and exact reference scope.Checked Boyd/Vandenberghe chapters 2-3 for convex set/function definitions, Jensen extensions, epigraph equivalence, and first-order global underestimator condition; checked MML for ML optimization/local-vs-global framing; checked Deep Learning Book chapter 8 for convex reference case and neural-network nonconvex caveats. GPT Pro publish critique remains pending.
Reviewer: codex-local-primary-source-audit; reviewed 2026-07-01Source support candidates
book 2004Convex OptimizationPrimary source for convex sets, convex functions, Jensen's inequality, epigraphs, first-order conditions, and global optimality in convex optimization.
book 2020Mathematics for Machine LearningConnects convexity to machine-learning optimization, gradients, loss functions, and mathematical prerequisites.
book 2016Deep LearningFrames convex optimization as a reference case for deep-learning optimization while emphasizing that neural-network objectives are usually nonconvex.
Practice Loop
Try the idea before it explains itself
Convexity is the mixture-preserving geometry that turns local checks into global optimization guarantees and underlies many ML losses and variational bounds.
Before touching the demo, predict one visible change that should happen in Convex Sets, Convex Functions, and Jensen's Inequality.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
Research Room
Attach the question to a claim, equation, code, or demo
Pick the concept, equation, source, runnable code, claim, misconception, or demo state before asking for help. The handoff keeps that page item in context.Open the draft below to save one note and next action in this browser.
Convex Sets, Convex Functions, and Jensen's Inequality
What is the smallest example that makes Convex Sets, Convex Functions, and Jensen's Inequality click without losing the math?
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays in this browser, attached to the selected learning item.
- References to inspect: attached references on this page.
- Definition, prerequisite, and contrast concept links
- The equation or runnable code that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - Convex Sets, Convex Functions, and Jensen's Inequality Selected item key: recorded for copy. Context: Optimization Page anchor: recorded for copy. Open question: What is the smallest example that makes Convex Sets, Convex Functions, and Jensen's Inequality click without losing the math? Evidence to inspect: - References to inspect: attached references on this page. - Definition, prerequisite, and contrast concept links - The equation or runnable code that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.
concept/concept-notebook/optimization/convex-sets-functions-jensen
concept:optimization/convex-sets-functions-jensen