Exercises

ex-sp-ch08-01

Easy

Minimize f(x,y)=(xβˆ’3)2+(y+1)2f(x, y) = (x-3)^2 + (y+1)^2 using scipy.optimize.minimize with method 'BFGS'. Provide the analytical gradient. Verify that the solution is (3,βˆ’1)(3, -1).

ex-sp-ch08-02

Easy

Use scipy.optimize.brentq to find the root of f(x)=exβˆ’3xf(x) = e^x - 3x on the interval [0,2][0, 2]. Verify by plugging back into ff.

ex-sp-ch08-03

Easy

Implement the soft-thresholding operator and apply it to the vector v=[βˆ’3,βˆ’1,0.5,0,2,βˆ’0.3,4]\mathbf{v} = [-3, -1, 0.5, 0, 2, -0.3, 4] with Ξ»=1\lambda = 1. How many components become exactly zero?

ex-sp-ch08-04

Easy

Solve the linear program: maximize 3x+5y3x + 5y subject to x+y≀10x + y \le 10, 2x+y≀142x + y \le 14, x,yβ‰₯0x, y \ge 0 using linprog.

ex-sp-ch08-05

Easy

Use scipy.optimize.fixed_point to find the fixed point of g(x)=cos⁑(x)g(x) = \cos(x) starting from x0=0.5x_0 = 0.5. Compare to the analytical value (Dottie number β‰ˆ0.73909\approx 0.73909).

ex-sp-ch08-06

Medium

Compare the iteration counts of Nelder-Mead, CG, BFGS, and Newton-CG on the Rosenbrock function f(x,y)=(1βˆ’x)2+100(yβˆ’x2)2f(x,y) = (1-x)^2 + 100(y-x^2)^2 from starting point (βˆ’1.5,2)(-1.5, 2). Provide analytical gradient and Hessian for the methods that use them.

ex-sp-ch08-07

Medium

Implement water-filling power allocation for N=12N=12 channels with total power P=20P=20. Channel gains are ∣hi∣2=10(20βˆ’3i)/10|h_i|^2 = 10^{(20 - 3i)/10} for i=0,…,11i = 0,\ldots,11. How many channels receive zero power? Verify with CVXPY.

ex-sp-ch08-08

Medium

Solve the LASSO problem for a 50Γ—20050 \times 200 random system with 10 true nonzeros using both CVXPY and ISTA. Compare the solutions and convergence.

ex-sp-ch08-09

Medium

Solve the system of nonlinear equations x2+y2=25x^2 + y^2 = 25, x2βˆ’y=3x^2 - y = 3 using fsolve from multiple starting points. Find all four solutions.

ex-sp-ch08-10

Medium

Implement the projection onto the probability simplex Ξ”n={xβ‰₯0:βˆ‘xi=1}\Delta_n = \{\mathbf{x} \ge 0 : \sum x_i = 1\} and test it on the vector v=[1.5,βˆ’0.5,0.3,0.8,βˆ’0.1]\mathbf{v} = [1.5, -0.5, 0.3, 0.8, -0.1]. Verify that the result satisfies the simplex constraints.

ex-sp-ch08-11

Medium

Use trust-constr to minimize f(x,y)=x2+y2f(x,y) = x^2 + y^2 subject to x+y=1x + y = 1 and xβ‰₯0.1x \ge 0.1, yβ‰₯0.1y \ge 0.1. Compare the result with the analytical solution.

ex-sp-ch08-12

Hard

Implement FISTA (Fast ISTA) for the LASSO problem and compare its convergence rate with ISTA on a 100Γ—500100 \times 500 random system. Plot f(xk)βˆ’f⋆f(\mathbf{x}_k) - f^\star vs iteration for both methods on a log scale.

ex-sp-ch08-13

Hard

Solve the SDP relaxation of MAX-CUT for a random graph with n=10n=10 nodes and edge probability 0.50.5. Implement Goemans-Williamson randomized rounding and compute the approximation ratio.

ex-sp-ch08-14

Hard

Implement Anderson acceleration for the fixed-point iteration x=0.5+sin⁑(x)/3x = 0.5 + \sin(x)/3 and compare convergence speed with plain iteration. Use history depth m=5m=5.

ex-sp-ch08-15

Hard

Implement the 1D total variation proximal operator using Chambolle's dual algorithm. Apply it to a noisy piecewise-constant signal (n=200n=200, 5 pieces, SNR=10 dB) and compare denoised output for different Ξ»\lambda values.

ex-sp-ch08-16

Hard

Use scipy.optimize.minimize with method='Newton-CG' providing only Hessian-vector products (via hessp) to minimize a logistic regression loss on a 1000Γ—501000 \times 50 dataset. Compare timing with full Hessian via hess.

ex-sp-ch08-17

Challenge

Implement ADMM (Alternating Direction Method of Multipliers) for the basis pursuit denoising problem min⁑βˆ₯xβˆ₯1Β s.t.Β βˆ₯Axβˆ’bβˆ₯2≀ϡ\min \|\mathbf{x}\|_1 \text{ s.t. } \|\mathbf{A}\mathbf{x} - \mathbf{b}\|_2 \le \epsilon. Compare with CVXPY's solution on a 30Γ—10030 \times 100 system with 5 true nonzeros.

ex-sp-ch08-18

Challenge

Formulate and solve a robust beamforming problem as an SOCP in CVXPY: minimize transmit power βˆ₯wβˆ₯22\|\mathbf{w}\|_2^2 subject to ∣a(ΞΈ0)Hw∣β‰₯1|\mathbf{a}(\theta_0)^H \mathbf{w}| \ge 1 and ∣a(ΞΈk)Hwβˆ£β‰€Ξ΄|\mathbf{a}(\theta_k)^H \mathbf{w}| \le \delta for interferer directions ΞΈk\theta_k, where a(ΞΈ)\mathbf{a}(\theta) is the steering vector for a ULA with n=8n=8 antennas.