6.4.8 · D3AI Safety & Alignment

Worked examples — Adversarial examples and robustness

3,895 words18 min readBack to topic

This page is the "muscle memory" companion to Adversarial examples and robustness. There we derived the Fast Gradient Sign Method and PGD. Here we run them by hand on tiny numbers so you can watch every gear turn — including the weird corners: zero gradients, gradients that vanish, the exact moment clipping bites, and a full targeted attack.

Before we do anything, the symbols we will lean on constantly:

Recall Where is

-optimality proven? The claim "under the best move is " is derived in the parent note (FGSM derivation, Steps 1–3). Quick reminder of why: we want to maximize the dot product . Each term is biggest when has the same sign as and is as large as allowed, namely . Hence maximizes every term at once.

The scenario matrix

Every worked example below is tagged with the cell(s) it covers. If a cell has no example, you have found a gap — there are none.

Cell What makes it tricky Covered by
A. All-positive gradient plain FGSM, every sign Ex 1
B. Mixed signs some pixels pushed up, some down Ex 2
C. Zero gradient entry : that pixel does not move Ex 3
D. Zero-vector gradient (degenerate) attack does nothing — a local flat/optimum Ex 3
E. Targeted attack (minus sign) drive toward a chosen class Ex 4
F. PGD with no clipping steps stay inside the ball, projection is idle Ex 5
G. PGD where projection bites a step leaves the -ball, clip pulls it back Ex 6
H. Pixel-range clipping (valid image) also clips Ex 6
I. High-dimensional accumulation why blows up Ex 7
J. Real-world word problem in RGB units Ex 8
K. Exam twist optimal step sign step Ex 9

The FGSM recipe on a 2-pixel image

Figure s01 (sketch it yourself): on axes "pixel 1" and "pixel 2", a teal square box of half-width is centred on the clean point . A plum arrow from points up-and-right along the gradient . FGSM lands on the orange top-right corner — the corner of the box most aligned with that arrow.

Figure — Adversarial examples and robustness

Figure s02 (sketch it yourself): the same teal box on , but now the plum gradient arrow points down-and-right (sign ), so FGSM snaps to the orange bottom-right corner — a different corner than Ex 1.

Figure — Adversarial examples and robustness

The degenerate cases: when the sign is zero


Targeted attacks: minus instead of plus


PGD by hand: watching the projection

FGSM takes one big leap of size . Projected Gradient Descent (PGD) instead takes several small steps, re-reading the gradient after each one, and "projects" (clips) back into the budget whenever a step wanders out. This finds stronger attacks because the loss surface bends, and one linear leap can overshoot or miss.

Figure s03 (sketch it yourself): PGD step number on the x-axis (), pixel value on the y-axis. A plum dashed line traces the pre-clip "raw" values climbing past (); a solid ink line shows the post-clip values flattening onto the orange ceiling at from step 1 on. A dotted teal line marks the looser -ceiling that never gets to bind because the pixel ceiling is tighter.

Figure — Adversarial examples and robustness

Why high dimensions are the attacker's friend


A real-world unit problem


The exam twist: ball changes the optimal step

Figure s04 (sketch it yourself): axes "delta 1" and "delta 2". Draw a teal circle of radius and a plum dashed square of half-width . An ink arrow points along the gradient . The orange -optimal dot sits on the circle at (on the gradient line); the plum "sign, rescaled" dot sits at — clearly not on the gradient line, showing the two attacks differ.

Figure — Adversarial examples and robustness

Recall Self-test

FGSM under uses which function of the gradient? ::: — direction only, magnitude discarded. equals? ::: — that pixel does not move. What does measure? ::: The largest single-pixel move, . What does do? ::: Returns — squashes into . Targeted FGSM uses plus or minus ? ::: Minus — we descend the target-class loss. In PGD, what does the step size satisfy and why? ::: , so no single step can jump the whole budget; the attack creeps and corrects course. In PGD, what does the clip/projection step guarantee? ::: The perturbation stays within the -ball around the original (and often within valid pixel range). Under an budget, the optimal points along what? ::: The gradient itself, scaled to length (not its sign). Why does high help the attacker? ::: Aligned per-pixel nudges accumulate; loss change grows like under a fixed budget.

See also: Gradient descent optimization (the same machinery, but PGD ascends the input not the weights), Neural network training, Out-of-distribution detection, Interpretability and explainability, and the framing in AI Safety fundamentals and Reward hacking.