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.

status: reviewimportance: criticaldifficulty 4/5math: graduateread: 18mlive demo

Concept Structure

Convex Sets, Convex Functions, and Jensen's Inequality

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

3prerequisites
5next concepts
4related links

Learner Contract

What this page should let you do.

You are here becauseConvexity is the mixture-preserving geometry that turns local checks into global optimization guarantees and underlies many ML losses and variational bounds.

This Optimization concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.

By the end4/4 sections ready | runnable code expected | live demo

Explain the mechanism, trace the main notation, and test one prediction in the live demo.

Do this firstIntuition

Read the intuition before the notation; the math should name a mechanism you already felt.

Test the linkManipulate one control and predict the visible change.Then continue to Lipschitz Smoothness and Strong Convexity (review)

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.
Claims1/1 reviewed
Sources3 cited
Codeattached
Demolive
Reviewed2026-07-01
Updatedpage 2026-07-01

Learning item flow

4/4 sections readyAsk about thisResearch room
ConceptConvex Sets, Convex Functions, and Jensen's InequalityOptimization
3 sources attachedLocal snapshot ready
concept:optimization/convex-sets-functions-jensen
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

Convexity is the geometry of mixing without surprise.

Take two points xx and yy. If every mixture between them,

θx+(1θ)yfor0θ1,\theta x + (1-\theta)y \quad\text{for}\quad 0\le \theta \le 1,

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, (x,f(x))(x,f(x)) and (y,f(y))(y,f(y)). 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

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Let CRdC\subseteq \mathbb{R}^d. The set CC is convex when for every x,yCx,y\in C and every θ[0,1]\theta\in[0,1],

θx+(1θ)yC.\theta x + (1-\theta)y \in C.

The vector θx+(1θ)y\theta x + (1-\theta)y is a weighted average of the two points. When θ=1\theta=1, it is xx; when θ=0\theta=0, it is yy; and for values in between it traces the line segment between them.

Let f:CRf:C\to\mathbb{R}, where CC is convex. The function ff is convex when for every x,yCx,y\in C and θ[0,1]\theta\in[0,1],

f(θx+(1θ)y)θf(x)+(1θ)f(y).f\big(\theta x+(1-\theta)y\big) \le \theta f(x)+(1-\theta)f(y).

The left side evaluates the function after mixing the inputs. The right side mixes the function values. Their difference,

Gθ(x,y)=θf(x)+(1θ)f(y)f(θx+(1θ)y),G_\theta(x,y) = \theta f(x)+(1-\theta)f(y) - f\big(\theta x+(1-\theta)y\big),

is the Jensen gap for this two-point mixture. Convexity says Gθ(x,y)0G_\theta(x,y)\ge 0 for every allowed pair and mixture weight.

Jensen's inequality extends the same idea to finitely many points. If ff is convex, x1,,xnCx_1,\ldots,x_n\in C, and weights αi0\alpha_i\ge0 satisfy i=1nαi=1\sum_{i=1}^n\alpha_i=1, then

f(i=1nαixi)i=1nαif(xi).f\left(\sum_{i=1}^n \alpha_i x_i\right) \le \sum_{i=1}^n \alpha_i f(x_i).

For a random variable XX with values in CC, and with the relevant expectations well-defined, the expectation version is

f(E[X])E[f(X)].f\big(\mathbb{E}[X]\big) \le \mathbb{E}[f(X)].

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 ff is

epi(f)={(x,t)C×R:f(x)t}.\operatorname{epi}(f)=\{(x,t)\in C\times\mathbb{R}: f(x)\le t\}.

The function ff is convex exactly when epi(f)\operatorname{epi}(f) is a convex set. Instead of looking at a curve and chords, you can look at the region above the graph.

Second, if ff is differentiable on a convex domain, then ff is convex exactly when every tangent plane is a global underestimator:

f(y)f(x)+f(x)(yx)for all x,yC.f(y)\ge f(x)+\nabla f(x)^\top (y-x) \quad\text{for all }x,y\in C.

This is the local-to-global bridge. For a differentiable convex function, any point xx^\star with f(x)=0\nabla f(x^\star)=0 satisfies

f(y)f(x)for all yC.f(y)\ge f(x^\star) \quad\text{for all }y\in C.

So xx^\star 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

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
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

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

Use the Jensen mixture lab to test the definition instead of just reading it.

In the Function chord stage, choose a function family, endpoints x,yx,y, and a mixture weight θ\theta. 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

θf(x)+(1θ)f(y)f(θx+(1θ)y).\theta f(x)+(1-\theta)f(y)-f(\theta x+(1-\theta)y).

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.

difficulty 4/5graduatecode-aligned
Demo Prediction Checkpoint

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.

Prediction open01 / Intuition
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

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.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

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.

book · 2004Convex OptimizationBoyd and Vandenberghe

Primary source for convex sets, convex functions, Jensen's inequality, epigraphs, first-order conditions, and global optimality in convex optimization.

Open source
book · 2020Mathematics for Machine LearningDeisenroth, Faisal, and Ong

Connects convexity to machine-learning optimization, gradients, loss functions, and mathematical prerequisites.

Open source
book · 2016Deep LearningGoodfellow, Bengio, and Courville

Frames convex optimization as a reference case for deep-learning optimization while emphasizing that neural-network objectives are usually nonconvex.

Open source

Claim Review

Convexity is the mixture-preserving geometry that turns local checks into global optimization guarantees and underlies many ML losses and variational bounds.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources3 references

boyd-2004-convex-optimization, deisenroth-2020-mml, goodfellow-2016-deep-learning

Local checks4 local checks

Use equations, runnable code, and demos to check whether the source support is operational.

Substantively reviewedConvex sets preserve line-segment mixtures, convex functions put the mixed-input value below the chord interpolation, Jensen's inequality extends that chord test to weighted averages and expectations, and differentiable convex functions have no non-global local minima.Claim metadata: source checked

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-01

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.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Convex Sets, Convex Functions, and Jensen's Inequality.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Grounded research drawerClose
ConceptConvex Sets, Convex Functions, and Jensen's InequalityOptimization

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.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptOptimization

Convex Sets, Convex Functions, and Jensen's Inequality

Attached question

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
Local action draft

This draft stays in this browser, attached to the selected learning item.

No local draft saved.
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
Grounded AI handoff

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.

View it in context
concept/concept-notebook/optimization/convex-sets-functions-jensen concept:optimization/convex-sets-functions-jensen