Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Stochastic optimization practice

Download the questions (PDF)

Allow about five minutes per exercise and briefly justify each answer. Exercises 1–10 cover streaming SGD and acceleration. Exercises 11–12 are optional.

Throughout, E denotes expectation and ‖⋅‖ denotes the Euclidean norm.

Streaming samples and SGD

1. Optimal order at a kink

A newsvendor chooses a real-valued order quantity q≥0q\geq0 and pays ℓ(q;D)=(q−D)++2(D−q)+\ell(q;D)=(q-D)_++2(D-q)_+, where (u)+=max⁡{u,0}(u)_+=\max\{u,0\}. Demand DD is 11, 22, or 44, with probabilities 1/41/4, 1/21/2, and 1/41/4, respectively. Find the slope of F(q)=𝔼ℓ(q;D)F(q)=\mathbb{E}\ell(q;D) immediately to the left and right of q=2q=2. Use the slopes to decide if q=2q=2 minimizes FF.

Solution to exercise 1

Immediately left of 22, the slope is 1/4−2(3/4)=−5/41/4-2(3/4)=-5/4. Immediately right of 22, it is 3/4−2(1/4)=1/43/4-2(1/4)=1/4. The slope crosses zero, so by convexity q=2q=2 is the unique minimizer. Equivalently, the subdifferential at 22 is [−5/4,1/4][-5/4,1/4], with zero in its interior.

2. What projection does to a mean update

Let 𝒳=[0,∞)\mathcal X=[0,\infty) and ℓ(x;ξ)=(x−ξ)2/2\ell(x;\xi)=(x-\xi)^2/2, where ξ=1\xi=1 or −1-1 with equal probabilities. At x=0x=0, take a projected SGD step x+=max⁡{0,x−tg},g=x−ξ,t=1/2.x^+=\max\{0,x-tg\},\qquad g=x-\xi,\qquad t=1/2. Compute 𝔼g\mathbb{E}g and 𝔼x+\mathbb{E}x^+. Compare the expected iterate with the projected step that uses the exact gradient F′(0)F'(0) for F(x)=𝔼ℓ(x;ξ)F(x)=\mathbb{E}\ell(x;\xi).

Solution to exercise 2

At zero, g=−ξg=-\xi has mean zero, and x+x^+ equals 1/21/2 when ξ=1\xi=1 and 00 when ξ=−1\xi=-1. Thus 𝔼x+=1/4\mathbb{E}x^+=1/4. Since F′(0)=0F'(0)=0, the exact projected step stays at 00. Projection clips one of the two moves and leaves the other intact.

3. When two workers share a random seed

At a fixed x∈ℝx\in\mathbb{R}, two workers run the same demand simulator to estimate a gradient. Each run returns g(x;ξ)=x+ξg(x;\xi)=x+\xi, where ξ=2\xi=2 or −2-2 with equal probabilities. In one case the workers draw independently. In the other, they accidentally use the same random seed, so their draws coincide. Find the mean and variance of the average of the two gradients in each case. Briefly explain why the variances differ.

Solution to exercise 3

The independent average is x+(ξ1+ξ2)/2x+(\xi_1+\xi_2)/2, with mean xx and variance (4+4)/4=2(4+4)/4=2 because the noises are independent. With a shared seed the average is x+(ξ+ξ)/2=x+ξx+(\xi+\xi)/2=x+\xi, with mean xx and variance 44. Both workers contribute the same sample in that case, so the average has the variance of a single draw.

4. When all samples share a minimizer

Let ℓ(x;ξ)=ξx2/2\ell(x;\xi)=\xi x^2/2, where ξ=1\xi=1 or 33 with equal probabilities. Starting at a fixed x0∈ℝx_0\in\mathbb{R}, run SGD with a fresh independent draw at each step and step size t=1/4t=1/4. Compute 𝔼[xk+12∣xk]\mathbb{E}[x_{k+1}^2\mid x_k]. Does the expected objective 𝔼F(xk)\mathbb{E}F(x_k) approach a positive noise floor, where F(x)=𝔼ℓ(x;ξ)F(x)=\mathbb{E}\ell(x;\xi)?

Solution to exercise 4

Since gk=ξkxkg_k=\xi_k x_k, the possible next iterates are 3xk/43x_k/4 and xk/4x_k/4, each with probability 1/21/2. Thus 𝔼[xk+12∣xk]=(5/16)xk2\mathbb{E}[x_{k+1}^2\mid x_k]=(5/16)x_k^2. Here F(x)=x2F(x)=x^2, so iterating expectations gives 𝔼F(xk)=(5/16)kx02→0\mathbb{E}F(x_k)=(5/16)^k x_0^2\to0. Each sampled gradient vanishes at the common minimizer x=0x=0.

5. Same demands, different regret

A vendor chooses qk∈[0,1]q_k\in[0,1] each day and pays |qk−Dk||q_k-D_k|. On day 00 the vendor orders q0=0q_0=0. On each later day the vendor orders the previous day’s demand, qk=Dk−1q_k=D_{k-1}. Compute the vendor’s four-day regret for each demand sequence (0,0,1,1)(0,0,1,1) and (0,1,0,1)(0,1,0,1), relative to the best fixed order on that sequence. Explain why the two regrets differ.

Solution to exercise 5

In either sequence each fixed order q∈[0,1]q\in[0,1] costs 2q+2(1−q)=22q+2(1-q)=2. The vendor pays 11 each time the demand switches, and pays 00 on the first day. The first sequence costs 11 with regret −1-1. The second costs 33 with regret 11. Both fixed-order costs depend only on demand counts, and the vendor’s costs depend on the order of arrival.

6. Two ways to report one iterate

Let FF be convex and let x0,…,xT−1x_0,\ldots,x_{T-1} be the iterates from a run of SGD with T≥1T\geq1. Given these iterates, draw JJ uniformly from {0,…,T−1}\{0,\ldots,T-1\}. Compare the conditional expected objective 𝔼[F(xJ)∣x0,…,xT−1]\mathbb{E}[F(x_J)\mid x_0,\ldots,x_{T-1}] with the objective at the average x‾T=T−1∑k=0T−1xk\bar x_T=T^{-1}\sum_{k=0}^{T-1}x_k. When can averaging be strictly better? Give a two-iterate example.

Solution to exercise 6

The conditional expectation is T−1∑k=0T−1F(xk)T^{-1}\sum_{k=0}^{T-1}F(x_k) by uniform sampling. Jensen’s inequality bounds F(x‾T)F(\bar x_T) above by that average. Strict convexity on the segment between two distinct iterates gives strict inequality for T=2T=2. For example, F(x)=x2F(x)=x^2 at iterates −1-1 and 11 gives conditional expected objective 11 for xJx_J and objective 00 for x‾T\bar x_T.

7. Shrink an estimate of the mean

Let ξ0,…,ξT−1\xi_0,\ldots,\xi_{T-1} be independent samples from a distribution with unknown mean m∈ℝm\in\mathbb{R} and variance σ2>0\sigma^2>0, with T≥1T\geq1. Write ξ‾=T−1∑k=0T−1ξk\bar\xi=T^{-1}\sum_{k=0}^{T-1}\xi_k and F(x)=𝔼[(x−ξ)2]/2F(x)=\mathbb{E}[(x-\xi)^2]/2, so F(x)−F⋆=(x−m)2/2F(x)-F^\star=(x-m)^2/2. You may use 𝔼[(Y−m)2]=Var⁡(Y)+(𝔼Y−m)2\mathbb{E}[(Y-m)^2]=\operatorname{Var}(Y)+(\mathbb{E}Y-m)^2. For which mm does x̂=ξ‾/2\widehat x=\bar\xi/2 have smaller expected objective gap than ξ‾\bar\xi? Explain how the comparison fits the lecture’s sample lower bound, which concerns the worst case over distributions.

Solution to exercise 7

For ξ‾\bar\xi the expected gap is σ2/(2T)\sigma^2/(2T). The estimator x̂\widehat x has mean m/2m/2 and variance σ2/(4T)\sigma^2/(4T), so its expected gap is (m2+σ2/T)/8(m^2+\sigma^2/T)/8. It improves on ξ‾\bar\xi exactly when m2<3σ2/Tm^2<3\sigma^2/T. It loses for sufficiently large |m||m| and its error grows without bound as |m||m| grows, consistent with a lower bound on the worst-case error over the family.

Acceleration and momentum

8. An easy instance with a large condition number

Consider f(x)=(x12+100x22)/2f(x)=(x_1^2+100x_2^2)/2 on ℝ2\mathbb{R}^2, with condition number κ=100\kappa=100. You may choose a different positive step size at each update xk+1=xk−tk∇f(xk)x_{k+1}=x_k-t_k\nabla f(x_k). Find two step sizes that reach the minimizer from every starting point in two gradient evaluations. Start by writing the update for each coordinate. How does the example fit the lecture’s lower bound for gradient methods?

Solution to exercise 8

The component multipliers of a step are 1−t1-t and 1−100t1-100t. Set t0=1/100t_0=1/100 to make the second coordinate zero, then set t1=1t_1=1 to make the first zero while preserving the second. The reverse order also works. The lower bound concerns a worst-case function in the smooth strongly convex class, in sufficiently large dimension. This particular quadratic has only two curvatures, both known.

9. Read the accelerated guarantee

For f(x)=3x2f(x)=3x^2, valid smoothness and strong convexity constants are L=9L=9 and μ=1\mu=1. Run Nesterov’s method from x−1=x0=1x_{-1}=x_0=1 with t=1/9t=1/9 and β=1/2\beta=1/2. The first step gives x1=1/3x_1=1/3. Find x2x_2 and x3x_3 and compare their objective values. Is the comparison consistent with the guarantee f(xk)−f⋆≤C(2/3)kf(x_k)-f^\star\leq C(2/3)^k for a constant CC?

Solution to exercise 9

The update is xk+1=(1−6/9)yk=yk/3x_{k+1}=(1-6/9)y_k=y_k/3 with yk=xk+(xk−xk−1)/2y_k=x_k+(x_k-x_{k-1})/2. Thus y1=0y_1=0 and x2=0x_2=0, then y2=−1/6y_2=-1/6 and x3=−1/18x_3=-1/18. The objective rises from 00 to 1/1081/108. The guarantee bounds each gap by a decreasing envelope, which can accommodate this increase. Here C=7/2C=7/2 in the lecture’s guarantee.

10. A momentum estimate after a large past gradient

At a step of SGD with momentum, condition on the current iterate and its history. The current true gradient is F′(xk)=1F'(x_k)=1, and the fresh sampled gradient gkg_k is 00 or 22 with equal probabilities. The previous momentum estimate is m̃k−1=3\tilde m_{k-1}=3 and the new estimate is m̃k=(m̃k−1+gk)/2\tilde m_k=(\tilde m_{k-1}+g_k)/2. Which of gkg_k and m̃k\tilde m_k has lower conditional variance? Which has lower conditional mean squared error about F′(xk)F'(x_k)?

Solution to exercise 10

The sampled gradient has mean 11, variance 11, and mean squared error 11. The momentum estimate is 3/23/2 or 5/25/2 with equal probabilities. Its conditional mean is 22, its variance is 1/41/4, and its mean squared error about 11 is 1/4+(2−1)2=5/41/4+(2-1)^2=5/4. Momentum has less variance, and the fresh gradient has less squared error because it is unbiased.

Optional heavy-ball problems

11. Opposite signs at the ends of the spectrum

For heavy ball on a quadratic, the scalar error along an eigenvector of curvature λ\lambda satisfies ek+1=(1+β−tλ)ek−βek−1e_{k+1}=(1+\beta-t\lambda)e_k-\beta e_{k-1}. Take t=1/4t=1/4 and β=1/4\beta=1/4. Compute the roots of z2−(1+β−tλ)z+β=0z^2-(1+\beta-t\lambda)z+\beta=0 for λ=1\lambda=1 and λ=9\lambda=9. What do the moduli say about the geometric decay factors? Which mode has an alternating sign factor?

Solution to exercise 11

At λ=1\lambda=1 the polynomial is (z−1/2)2(z-1/2)^2, with repeated root 1/21/2. At λ=9\lambda=9 it is (z+1/2)2(z+1/2)^2, with repeated root −1/2-1/2. Both have geometric decay factor 1/21/2. The λ=9\lambda=9 mode has an alternating factor (−1)k(-1)^k. The repeated roots can also introduce a factor linear in kk.

12. Heavy ball and two-point cycles

Let f:ℝd→ℝf\colon\mathbb{R}^d\to\mathbb{R} be LL-smooth with L>0L>0. Run heavy ball with 0<t≤1/L0<t\leq1/L and 0≤β<10\leq\beta<1, using the update xk+1=xk+β(xk−xk−1)−t∇f(xk).x_{k+1}=x_k+\beta(x_k-x_{k-1})-t\nabla f(x_k). Could the iterates alternate forever between two distinct points aa and bb? Write the update at aa and at bb, then subtract the equations and use smoothness to justify your answer.

Solution to exercise 12

The update from aa to bb gives t∇f(a)=(1+β)(a−b)t\nabla f(a)=(1+\beta)(a-b), and the update from bb to aa gives t∇f(b)=(1+β)(b−a)t\nabla f(b)=(1+\beta)(b-a). Subtracting and applying smoothness gives 2(1+β)∥a−b∥=t∥∇f(a)−∇f(b)∥≤tL∥a−b∥≤∥a−b∥.2(1+\beta)\|a-b\| =t\|\nabla f(a)-\nabla f(b)\| \leq tL\|a-b\|\leq\|a-b\|. Since 2(1+β)≥22(1+\beta)\geq2 and a≠ba\ne b, the inequality is impossible.