Xiangxiong Zhang MA 574 · Numerical Optimization · Purdue University · Fall 2026

Some examples from applications

Optimization problems that come up in machine learning and signal processing, each with a runnable MATLAB demo. Every demo is a plain .m file — download it and run it in MATLAB.

Smooth problems — gradient descent and its variants

Relevant to Part I of the course: the objective is differentiable, but nonconvex.

1. Regression with a convolutional network

Predicting a continuous output from input features — house prices, molecular binding energies, weather fields. With data $\{(a_i,b_i)\}_{i=1}^n$ and a network $\Phi(\cdot\,;x)$, training minimizes the mean squared error \[ f(x)=\frac1n\sum_{i=1}^n \bigl\|\Phi(a_i;x)-b_i\bigr\|^2. \] With smooth activations (sigmoid, tanh, softplus, GELU), $f$ is a smooth function of the parameters $x$, so this is exactly the setting of Part I.

MATLAB demo: cnn_regression.m — trains a CNN to fit $f(x)=\sin(2x)+0.5\cos(5x)+0.3\sin(8x)$ using Gabor-like patch encoding and the Adam optimizer.

Plots from the CNN regression demo: the fitted curve against the target function, together with the training loss decreasing over epochs.
CNN regression: fitted curve and training history.

2. Denoising diffusion models

Diffusion models (DDPM, Stable Diffusion, DALL·E 2) generate images by learning to reverse a noise-corruption process. A network $\epsilon_\theta$ is trained to predict the noise added at diffusion step $t$: \[ \mathcal{L}(\theta)=\mathbb{E}_{t,x_0,\epsilon}\bigl[\|\epsilon-\epsilon_\theta(x_t,t)\|^2\bigr], \qquad x_t=\sqrt{\bar\alpha_t}\,x_0+\sqrt{1-\bar\alpha_t}\,\epsilon. \]

Why this is still a smooth problem: smoothness concerns how $\mathcal{L}$ depends on the optimization variable $\theta$, not on the random $(t,x_0,\epsilon)$ or on the sampling procedure used at inference. For each fixed $(t,x_0,\epsilon)$ the integrand is smooth in $\theta$, and the expectation preserves smoothness.

MATLAB demo: diffusion_2d_demo.m — trains a 6-layer fully connected network (512 units, sinusoidal timestep embeddings) on a 2D “two moons” dataset with a cosine noise schedule and a momentum optimizer.

Results of the 2D diffusion demo, showing generated samples reproducing the two-moons distribution alongside the training loss curve.
Generated samples and training loss.
Forward diffusion process: the two-moons point cloud is progressively corrupted until it becomes an isotropic Gaussian blob.
Forward process: data → noise.
Reverse generation process: starting from Gaussian noise, the learned model progressively denoises the points back into the two-moons shape.
Reverse process: noise → data.

3. Autoencoders

An autoencoder learns a compressed representation by training an encoder–decoder pair to reconstruct its own input: \[ \mathcal{L}(\theta)=\frac1n\sum_{i=1}^n \bigl\|D_\theta(E_\theta(a_i))-a_i\bigr\|^2. \] Applications include dimensionality reduction, denoising, and anomaly detection. Variational autoencoders add a KL-divergence regularizer but keep this MSE reconstruction term.

MATLAB demo: autoencoder_pointcloud.m — trains a fully connected autoencoder (150→128→64→32→2→32→64→128→150) that compresses 3D point clouds from 5 shape classes into a 2D latent space.

Autoencoder training results: reconstruction loss decreasing over epochs and a scatter plot of the two-dimensional latent space with the five shape classes separated into clusters.
Autoencoder training and the 2D latent space.

4. Pretraining a small language model (BERT-Tiny)

Masked language model pretraining is a smooth nonconvex problem: BERT-Tiny uses GELU activations, softmax attention, LayerNorm, and cross-entropy loss, all smooth, so unlike a ReLU network the loss is differentiable everywhere in the parameters.

Note that a masked language model is not a chatbot: it fills in blanks, whereas an LLM such as ChatGPT generates text autoregressively and adds instruction tuning and RLHF.

Training curve for BERT-Tiny masked language model pretraining on WikiText-2, showing the loss decreasing steadily over one hundred thousand steps.
AdamW converges steadily on this smooth nonconvex landscape.
Side-by-side comparison of masked-token predictions from the small BERT-Tiny model trained here and from Google's much larger pretrained BERT-Base, with the larger model giving markedly better predictions.
BERT-Tiny (4.4M params) vs Google's BERT-Base (110M): scale matters.
Examples of Google's pretrained BERT filling in masked tokens in two sentences, listing the top candidate words with their probabilities.
Pretrained BERT filling in masked tokens.
Convex nonsmooth problems — proximal and splitting methods

Relevant to Part II of the course.

5. Sparse recovery: basis pursuit and the LASSO

Sparse and regularized models (LASSO, elastic net, group LASSO) use $\ell_1$-type penalties, giving nonsmooth convex objectives. The subgradient method applies but is slow, $O(1/\sqrt k)$, and its iterates are not sparse. Exploiting the composite structure $F=f+g$ instead gives the proximal gradient method, where for $g=\lambda\|\cdot\|_1$ the proximal operator is soft-thresholding \[ [\mathrm{prox}_{\alpha\lambda\|\cdot\|_1}(z)]_j=\mathrm{sign}(z_j)\max\bigl(|z_j|-\alpha\lambda,\,0\bigr), \] so every iterate is exactly sparse. The rate is $O(1/k)$ for ISTA and $O(1/k^2)$ for FISTA.

MATLAB demo: douglas_rachford_basis_pursuit.m — solves $\min\|x\|_1$ subject to $Ax=b$ by Douglas–Rachford splitting, alternating affine projection and soft thresholding. It recovers a sparse signal (20 nonzeros in 1000 dimensions) from 100 measurements. For this problem Douglas–Rachford is equivalent to ADMM and to the split Bregman method.

Nonconvex and nonsmooth problems

Where the classical theory of Parts I and II no longer applies.

6. Classification with a ReLU network

A ReLU network is a composition of affine maps and the nonsmooth activation $\sigma(t)=\max(t,0)$, which is not differentiable at $t=0$. The training loss is therefore both nonconvex and nonsmooth, and the same is true of networks using max-pooling or dropout. This is the regime that motivates the Clarke subdifferential and the Kurdyka–Łojasiewicz theory.

MATLAB demo: cnn_classification.m — trains a CNN to classify a 4-class spiral dataset in 2D using 2D patch encoding, and shows how the decision boundary evolves during training. Concepts: cross-entropy loss, softmax, ReLU, decision boundaries, training/validation split.

CNN classification results on a four-class spiral dataset: the learned decision boundary separating the four interleaved spiral arms, together with training and validation accuracy curves.
Decision boundary and training curves on the 4-class spiral data.

More detail on every example, including the convergence theory behind them, is in the seminar slides.