-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07-ContinuousOptimization.Rmd
More file actions
1756 lines (1311 loc) · 40.5 KB
/
07-ContinuousOptimization.Rmd
File metadata and controls
1756 lines (1311 loc) · 40.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Continuous Optimization
Machine learning training often involves finding the best set of parameters that minimize an objective function, which measures how well a model fits the data. This search for optimal parameters is formulated as a **continuous optimization problem**, since the parameters typically take values in \( \mathbb{R}^D \).
Optimization problems can be divided into two main types:
- **Unconstrained optimization**, where parameters can take any value in \( \mathbb{R}^D \).
- **Constrained optimization**, where parameters must satisfy specific restrictions.
Most objective functions in machine learning are differentiable, allowing the use of gradients to find minima. The gradient points in the direction of steepest ascent, so algorithms typically move in the opposite direction (downhill) to minimize the function. The step size determines how far to move along this direction.
The goal is to find points where the gradient is zero — these are **stationary points**. A stationary point can be:
- A **local minimum** (second derivative \( > 0 \)),
- A **local maximum** (second derivative \( < 0 \)), or
- A **saddle point**.
An example function
\[
\ell(x) = x^4 + 7x^3 + 5x^2 - 17x + 3
\]
demonstrates multiple stationary points — two minima and one maximum — found by setting the derivative
\[
\frac{d\ell(x)}{dx} = 4x^3 + 21x^2 + 10x - 17 = 0
\]
to zero and analyzing the sign of the second derivative.
In practice, analytical solutions are often not feasible, especially for high-degree polynomials (by the Abel–Ruffini theorem, equations of degree ≥5 cannot be solved algebraically). Instead, we rely on numerical optimization algorithms that iteratively follow the negative gradient.
A key concept introduced later in the chapter is **convex optimization**. For **convex functions**, every local minimum is also a global minimum, which guarantees that gradient-based methods will converge to the optimal solution regardless of the starting point. Many machine learning objectives are designed to be convex for this reason.
While the examples here are one-dimensional, the same principles extend to multidimensional optimization, though visualization becomes more challenging. Gradients, step directions, and curvature generalize to higher-dimensional parameter spaces.
<p align="center">
<img src="Figure7.1MML.png" alt="A mind map of the concepts related to optimization, as
presented in this chapter. There are two main ideas: gradient descent and convex optimization." width="400">
</p>
## Optimization Using Gradient Descent
Optimization methods are central to training machine learning models. In this section, we study **gradient-based optimization**, where we iteratively improve parameters by following the negative gradient of an objective function.
Gradient descent is a **first-order optimization algorithm** used to find a local minimum of a differentiable function \( f: \mathbb{R}^d \to \mathbb{R} \).
<div class="definition">
The **gradient descent** algorithm begins with an initial guess $\mathbf{x}_0$. At each iteration, parameters are updated as:
\[
\mathbf{x}_{i+1} = \mathbf{x}_i - \gamma_i (\nabla f(\mathbf{x}_i))^\top ,
\]
where \( \gamma_i \) is the **step-size** (or **learning rate**).
</div>
The gradient points in the direction of steepest ascent, so moving in the opposite direction decreases the function value.
<div class="example">
Gradient Descent on a Simple Quadratic Function
Consider the quadratic function
\[
f(x) = (x - 3)^2.
\]
This function has a **global minimum** at \( x = 3 \).
The derivative (gradient) of \( f \) is
\[
\nabla f(x) = f'(x) = 2(x - 3).
\]
Gradient descent updates the variable \( x \) according to
\[
x_{k+1} = x_k - \gamma \nabla f(x_k),
\]
where \( \gamma > 0 \) is the **learning rate**.
Substituting the gradient:
\[
x_{k+1} = x_k - \gamma \, 2(x_k - 3).
\]
Let the initial value be \( x_0 = 0 \) and choose \( \gamma = 0.1 \).
\[
x_1 = 0 - 0.1 \cdot 2(0 - 3) = 0.6
\]
\[
x_2 = 0.6 - 0.1 \cdot 2(0.6 - 3) = 1.08
\]
\[
x_3 = 1.08 - 0.1 \cdot 2(1.08 - 3) = 1.464
\]
Each step moves \( x_k \) closer to the minimizer \( x = 3 \).
The gradient points in the direction of steepest increase. Gradient descent moves in the opposite direction, reducing the function value. Because \( f(x) \) is convex, gradient descent converges to the global minimum.
</div>
A simple example with a quadratic function demonstrates how iterative updates move toward the minimum value. However, if the problem is poorly conditioned (e.g., shaped like a long narrow valley), convergence becomes slow and oscillatory.
<div class="example">
Gradient Descent on a Two-Variable Quadratic Function
Consider the function
\[
f(x, y) = (x - 2)^2 + (y + 1)^2.
\]
This is a **convex quadratic** function with a global minimum at
\[
(x^\ast, y^\ast) = (2, -1).
\]
The gradient of \( f \) is
\[
\nabla f(x, y)
=
\begin{bmatrix}
\frac{\partial f}{\partial x} \\
\frac{\partial f}{\partial y}
\end{bmatrix}
=
\begin{bmatrix}
2(x - 2) \\
2(y + 1)
\end{bmatrix}.
\]
Gradient descent updates the variables according to
\[
\begin{bmatrix}
x_{k+1} \\
y_{k+1}
\end{bmatrix}
=
\begin{bmatrix}
x_k \\
y_k
\end{bmatrix}
-
\gamma
\begin{bmatrix}
2(x_k - 2) \\
2(y_k + 1)
\end{bmatrix},
\]
where \( \gamma > 0 \) is the **learning rate**.
Let the initial point be
\[
(x_0, y_0) = (0, 0),
\]
and choose \( \gamma = 0.1 \).
- **Iteration 1**
\[
\begin{aligned}
x_1 &= 0 - 0.1 \cdot 2(0 - 2) = 0.4, \\
y_1 &= 0 - 0.1 \cdot 2(0 + 1) = -0.2.
\end{aligned}
\]
- **Iteration 2**
\[
\begin{aligned}
x_2 &= 0.4 - 0.1 \cdot 2(0.4 - 2) = 0.72, \\
y_2 &= -0.2 - 0.1 \cdot 2(-0.2 + 1) = -0.36.
\end{aligned}
\]
- **Iteration 3**
\[
\begin{aligned}
x_3 &= 0.72 - 0.1 \cdot 2(0.72 - 2) = 0.976, \\
y_3 &= -0.36 - 0.1 \cdot 2(-0.36 + 1) = -0.488.
\end{aligned}
\]
The iterates move steadily toward \( (2, -1) \).
The level sets of \( f(x,y) \) are concentric circles centered at \( (2,-1) \). The gradient points perpendicular to level curves in the direction of steepest increase. Gradient descent moves opposite the gradient, descending toward the minimum.
</div>
### Step-size Selection
Choosing an appropriate step-size \( \gamma \) is crucial:
- **Too small** → slow convergence
- **Too large** → overshooting or divergence
Adaptive methods adjust the step-size based on local function behavior:
- If \( f(x_{i+1}) > f(x_i) \), the step was too large → reduce \( \gamma \)
- If \( f(x_{i+1}) < f(x_i) \), the step could be larger → increase \( \gamma \)
This ensures monotonic convergence. **Monotonic convergence** refers to a type of convergence where a sequence approaches its limit **without oscillating**, meaning it moves consistently in one direction (either always increasing or always decreasing) toward the limit.
<div class="definition">
A sequence \( \{x_n\} \) **converges monotonically** to \( x^\ast \) if it satisfies both:
1. \( x_n \to x^\ast \) as \( n \to \infty \), and
2. The sequence is **monotonic**, meaning either:
- \( x_{n+1} \le x_n \) for all \( n \) (monotonic decreasing), or
- \( x_{n+1} \ge x_n \) for all \( n \) (monotonic increasing).
</div>
<div class="example">
Solving \( \mathbf{A}\mathbf{x} = \mathbf{b} \) can be formulated as minimizing:
\[
\|\mathbf{A}\mathbf{x} - \mathbf{b}\|^2 = (\mathbf{A}\mathbf{x} - \mathbf{b})^\top (\mathbf{A}\mathbf{x} - \mathbf{b}).
\]
The gradient is \[ \nabla_\mathbf{x} = 2(\mathbf{A}\mathbf{x} - \mathbf{b})^\top \mathbf{A} .\] Although this problem has a closed-form solution, gradient descent provides an iterative alternative.
</div>
The **convergence rate** depends on the **condition number** \( \kappa = \frac{\sigma_{\max}(\mathbf{A})}{\sigma_{\min}(\mathbf{A})} \) (here, $\sigma_{max}$ and $\sigma_{min}$ refer to the maximum and minimum singular values of $\mathbf{A}$). You can imagine a poorly conditioned problem as one similar to trying to find the minimum value of a slightly curved dinner plate versus a well conditioned problem as trying to find the minimum of an ice-cream cone. Poorly conditioned problems have small condition number while better conditioned ones have large condition numbers.
Preconditioning (using a matrix \( \mathbf{P}^{-1} \) or $\mathbf{P}$ in some texts) can improve convergence. The idea of preconditioning is essentially solving \[\mathbf{P}^{-1}\left(\mathbf{A}\mathbf{x} - \mathbf{b} \right) = \mathbf{0}\] instead of the original.
<div class="example">
Preconditioning Gradient Descent
Consider the quadratic function
\[
f(\mathbf{x}) = \frac{1}{2}\mathbf{x}^\top \mathbf{A}\mathbf{x},
\quad
\mathbf{x} =
\begin{bmatrix}
x_1 \\ x_2
\end{bmatrix},
\]
where
\[
\mathbf{A} =
\begin{bmatrix}
10 & 0 \\
0 & 1
\end{bmatrix}.
\]
This function is **strongly anisotropic**: it curves much more steeply in the
\(x_1\)-direction than in the \(x_2\)-direction.
The gradient is
\[
\nabla f(\mathbf{x}) = \mathbf{A}\mathbf{x}
=
\begin{bmatrix}
10x_1 \\
x_2
\end{bmatrix}.
\]
Standard gradient descent updates:
\[
\mathbf{x}_{k+1} = \mathbf{x}_k - \gamma \nabla f(\mathbf{x}_k).
\]
Because of the large eigenvalue \(10\), the method must take **small steps** to avoid overshooting, leading to slow convergence.
We choose a **preconditioning matrix**
\[
\mathbf{P} =
\begin{bmatrix}
\frac{1}{10} & 0 \\
0 & 1
\end{bmatrix}.
\]
The preconditioned gradient descent update becomes
\[
\mathbf{x}_{k+1}
=
\mathbf{x}_k - \gamma \mathbf{P}\nabla f(\mathbf{x}_k).
\]
The impact of this is the new preconditioned gradient:
\[
\mathbf{P}\nabla f(\mathbf{x})
=
\begin{bmatrix}
\frac{1}{10} & 0 \\
0 & 1
\end{bmatrix}
\begin{bmatrix}
10x_1 \\
x_2
\end{bmatrix}
=
\begin{bmatrix}
x_1 \\
x_2
\end{bmatrix}.
\]
Now the update rule is
\[
\mathbf{x}_{k+1}
=
\mathbf{x}_k - \gamma
\begin{bmatrix}
x_1 \\
x_2
\end{bmatrix}.
\]
Both components are scaled **equally**, eliminating the imbalance in curvature.
Without preconditioning: level sets are **elongated ellipses**, causing zig-zag motion. With preconditioning: the problem behaves like
\[
f(\mathbf{x}) = \tfrac{1}{2}(x_1^2 + x_2^2),
\]
which has circular level sets. Convergence is faster and more stable.
</div>
### Gradient Descent with Momentum
Gradient descent with momentum adds a memory term to smooth updates and dampen oscillations:
\[
\mathbf{x}_{i+1} = \mathbf{x}_i - \gamma_i (\nabla f(\mathbf{x}_i))^\top + \alpha \Delta \mathbf{x}_i
\]
where \( \Delta \mathbf{x}_i = \mathbf{x}_i - \mathbf{x}_{i-1} \) and \( \alpha \in [0,1] \) controls the contribution of past updates.
This technique behaves like a heavy ball rolling downhill, accelerating along consistent directions and reducing oscillations in narrow valleys. Momentum helps especially when gradients are noisy or the optimization landscape is highly curved.
<div class="example">
Gradient Descent with Momentum
Consider the one–dimensional quadratic function
\[
f(x) = x^2.
\]
The gradient is
\[
\nabla f(x) = 2x.
\]
Momentum introduces a **velocity** term \(v_k\):
\[
\begin{aligned}
v_{k+1} &= \beta v_k + \nabla f(x_k), \\
x_{k+1} &= x_k - \gamma v_{k+1},
\end{aligned}
\]
where:
- \( \gamma > 0 \) is the learning rate,
- \( \beta \in [0,1) \) is the momentum parameter.
For example, let:
\[
x_0 = 4, \quad v_0 = 0, \quad \gamma = 0.1, \quad \beta = 0.9.
\]
- Gradient at \(x_0\):
\[
\nabla f(x_0) = 2(4) = 8
\]
- Velocity update:
\[
v_1 = 0.9(0) + 8 = 8
\]
- Position update:
\[
x_1 = 4 - 0.1(8) = 3.2.
\]
Momentum accumulates past gradients, helping the iterates move faster in consistent descent directions and reducing oscillations.
- Gradient at \(x_1\):
\[
\nabla f(x_1) = 2(3.2) = 6.4
\]
- Velocity update:
\[
v_2 = 0.9(8) + 8 = 7.2
\]
- Position update:
\[
x_2 = 3.2 - 0.1(7.2) = 2.48.
\]
</div>
### Stochastic Gradient Descent (SGD)
**Stochastic Gradient Descent (SGD)** approximates the gradient using a random subset of data. Given a loss function decomposed as a sum:
\[
L(\mathbf{\theta}) = \sum_{n=1}^N L_n(\mathbf{\theta}),
\]
SGD updates parameters using only a subset (mini-batch) of terms:
\[
\mathbf{\theta}_{i+1} = \mathbf{\theta}_i - \gamma_i \left( \nabla L(\mathbf{\theta}_i) \right)^\top
= \mathbf{\theta}_i - \gamma_i \sum_{n=1}^N \left( \nabla L_{n}(\mathbf{\theta}_i) \right)^\top.
\]
This reduces computational cost and allows training on large datasets.
- **Large mini-batches** → lower variance, smoother convergence, but higher cost
- **Small mini-batches** → noisier updates, faster per-step computation, better ability to escape local minima
Despite noisy gradients, SGD converges to a local minimum (almost surely) under mild conditions. It has become the default optimization method in large-scale machine learning.
<div class="example">
Stochastic Gradient Descent (SGD)
Consider a dataset with three data points and the loss function
\[
f(x) = \frac{1}{3}\sum_{i=1}^3 f_i(x),
\quad
f_i(x) = (x - a_i)^2,
\]
where:
\[
a_1 = 1, \quad a_2 = 3, \quad a_3 = 5.
\]
**Full Gradient (Batch Gradient Descent)**
\[
\nabla f(x) = \frac{2}{3}\sum_{i=1}^3 (x - a_i).
\]
**Stochastic Gradient Descent Update**
SGD uses **one data point at a time**:
\[
x_{k+1} = x_k - \gamma \nabla f_{i_k}(x_k),
\]
where \( i_k \) is chosen randomly from \( \{1,2,3\} \).
For example, let:
\[
x_0 = 0, \quad \gamma = 0.1,
\]
and randomly choose \( i_0 = 2 \).
- Gradient using only \( f_2 \):
\[
\nabla f_2(x_0) = 2(x_0 - 3) = -6
\]
- Update:
\[
x_1 = 0 - 0.1(-6) = 0.6
\]
Here, the update is noisy, but cheap. On average, SGD moves toward the minimum. It is widely used in machine learning for large datasets.
</div>
---
### Exercises {.unnumbered .unlisted}
<div class="exercise">
The notes talk about a function \[f\left(\begin{bmatrix}x_1\\x_2 \end{bmatrix}\right) = \dfrac{1}{2}\begin{bmatrix}x_1\\x_2 \end{bmatrix}^T\begin{bmatrix}2 & 1 \\ 1 & 20 \end{bmatrix} \begin{bmatrix}x_1\\x_2 \end{bmatrix} - \begin{bmatrix}5\\3 \end{bmatrix}^T\begin{bmatrix}x_1\\x_2 \end{bmatrix}.\] What is this function? Show that the gradient is \[\nabla f\left(\begin{bmatrix}x_1\\x_2 \end{bmatrix}\right) = \dfrac{1}{2}\begin{bmatrix}x_1\\x_2 \end{bmatrix}^T\begin{bmatrix}2 & 1 \\ 1 & 20 \end{bmatrix} - \begin{bmatrix}5\\3 \end{bmatrix}^T.\]
<div style="text-align: right;">
[Solution]( )
</div>
</div>
<div class="exercise">
Let \[f(x) = \dfrac{x^2 \cos(x) - x}{10},\] with $x_0 = 6$ and stepsize 0.2. Use gradient descent to find the local minimum. Stop when successive terms are within 0.05 of each other.
<div style="text-align: right;">
[Solution]( )
</div>
</div>
<div class="exercise">
Let \[f(x) = xe^{-x^2} + \dfrac{x^2}{20}.\] Run 10 iterations of gradient descent from the initial position $x_0 = -3$ and step size 0.1 to try to find the minimum of $f$.
<div style="text-align: right;">
[Solution]( )
</div>
</div>
<div class="exercise">
Let \[f(x,y) = \left(\dfrac{3}{4}x - \dfrac{3}{2} \right)^2 + (y-2)^2 + \dfrac{1}{4} xy.\] Run 10 iterations of gradient descent from the initial position $(5,4)$ with step sizes 1, 0.1 and 0.01 to try to find the minimum of $f$.
<div style="text-align: right;">
[Solution]( )
</div>
</div>
<div class="exercise">
Let \[f(x,y) = e^{-x^2-y^2} + \dfrac{x^2+y^2}{20}.\] Run 10 iterations of gradient descent from the initial position $(1,1)$ with step sizes 1, 0.1 and 0.01 to try to find the minimum of $f$.
<div style="text-align: right;">
[Solution]( )
</div>
</div>
<div class="exercise">
Use gradient descent for 5 iterations and initial guess $\mathbf{x}_0 = [4,2,-1]$ to find the minimum of \[f(x,y,z) = (x-4)^4 + (y-3)^2 + 4(z-5)^4.\]
<div style="text-align: right;">
[Solution]( )
</div>
</div>
## Constrained Optimization and Lagrange Multipliers
In many optimization problems, we seek to minimize a function \( f( \mathbf{x}) \) **subject to constraints** on the variables \( \mathbf{x} \).
<div class="definition">
A constrained optimization problem has the form:
\[
\min_{\mathbf{x}} f( \mathbf{x}) \quad \text{subject to } g_i( \mathbf{x}) \le 0, \; i = 1, \ldots, m
\]
where each \( g_i( \mathbf{x}) \) defines a constraint.
</div>
---
### From Constraints to the Lagrangian
Rather than directly enforcing the constraints, another approach is to penalize violations of the constraints using an **indicator function**:
\[
J( \mathbf{x}) = f( \mathbf{x}) + \sum_{i=1}^{m} \mathbf{1}(g_i(\mathbf{x}))
\quad \text{where} \quad
\mathbf{1}(z) =
\begin{cases}
0 & \text{if } z \le 0,\\
\infty & \text{otherwise.}
\end{cases}
\]
However, this is difficult to optimize because this indicator function is non-differentiable. To overcome this, we introduce **Lagrange multipliers** \( \mathbf{\lambda}_i \ge 0 \) and form the **Lagrangian**:
\[
L(\mathbf{x}, \mathbf{\mathbf{\lambda}}) = f(\mathbf{x}) + \sum_{i=1}^{m} \mathbf{\mathbf{\lambda}}_i g_i(\mathbf{x})
= f(\mathbf{x}) + \mathbf{\mathbf{\lambda}}^\top \mathbf{g}(\mathbf{x})
\]
To solve a Lagrange multiplier problem, we solve \[L(\mathbf{x}, \mathbf{\lambda})=0.\] That's the same as solving $\nabla f = \lambda \nabla g$ with $g(\mathbf{x}) = 0$.
<div class="example">
Find the maximum and minimum of the function
\[
f(x,y) = x^2 + y^2
\]
subject to the constraint
\[
g(x,y) = x + y - 4 = 0.
\]
First, we find the gradients
\[
\nabla f(x,y) =
\begin{bmatrix}
2x \\
2y
\end{bmatrix},
\qquad
\nabla g(x,y) =
\begin{bmatrix}
1 \\
1
\end{bmatrix}.
\]
The Lagrange multiplier condition is
\[
\nabla f = \lambda \nabla g.
\]
This gives:
\[
\begin{cases}
2x = \lambda \\
2y = \lambda \\
x + y = 4
\end{cases}
\]
From the first two equations:
\[
2x = 2y \quad \Rightarrow \quad x = y.
\]
Substitute into the constraint:
\[
x + x = 4 \quad \Rightarrow \quad x = 2.
\]
Thus:
\[
(x,y) = (2,2).
\]
The minimum value is
\[
f(2,2) = 2^2 + 2^2 = 8.
\]
No maximum value exists since we can make $x^2 + y^2$ as large as we like when $x+y-4 = 0$. We would need a restriction on the size of $x$ and $y$ to find both the max and min values.
</div>
---
#### Lagrangian Duality
<div class="definition">
The **primal problem** is:
\[
\min_x f(\mathbf{x}) \quad \text{subject to } g_i(\mathbf{x}) \le 0
\]
</div>
<div class="definition">
The corresponding **Lagrangian dual problem** is:
\[
\max_{\mathbf{\lambda} \ge 0} D(\mathbf{\mathbf{\lambda}})
\quad \text{where} \quad
D(\mathbf{\mathbf{\lambda}}) = \min_x L(\mathbf{x}, \mathbf{\mathbf{\lambda}})
\]
</div>
This dual formulation often simplifies computation since \( D(\mathbf{\mathbf{\lambda}}) \) is concave, even if \( f \) and \( g_i \) are not.
<div class="example">
Consider the constrained optimization problem:
\[
\begin{aligned}
\min_{x \in \mathbb{R}} \quad & f(x) = x^2 \\
\text{subject to} \quad & g(x) = x - 1 \le 0.
\end{aligned}
\]
This means we want to minimize \(x^2\) subject to \(x \le 1\).
We introduce a Lagrange multiplier \(\lambda \ge 0\) for the inequality constraint:
\[
\mathcal{L}(x, \lambda) = x^2 + \lambda(x - 1).
\]
The **dual function** is obtained by minimizing the Lagrangian over \(x\):
\[
g(\lambda) = \inf_{x \in \mathbb{R}} \mathcal{L}(x, \lambda).
\]
Take the derivative with respect to \(x\) and set it to zero:
\[
\frac{d}{dx}(x^2 + \lambda x - \lambda) = 2x + \lambda = 0
\quad \Rightarrow \quad
x^* = -\frac{\lambda}{2}.
\]
Substitute back:
\[
\begin{aligned}
g(\lambda)
&= \left(-\frac{\lambda}{2}\right)^2
+ \lambda\left(-\frac{\lambda}{2} - 1\right) \\
&= \frac{\lambda^2}{4} - \frac{\lambda^2}{2} - \lambda \\
&= -\frac{\lambda^2}{4} - \lambda.
\end{aligned}
\]
The *dual problem* is:
\[
\begin{aligned}
\max_{\lambda \ge 0} \quad & g(\lambda)
= -\frac{\lambda^2}{4} - \lambda.
\end{aligned}
\]
We differentiate:
\[
\frac{d}{d\lambda}\left(-\frac{\lambda^2}{4} - \lambda\right)
= -\frac{\lambda}{2} - 1,
\]
and set equal to zero:
\[
-\frac{\lambda}{2} - 1 = 0
\quad \Rightarrow \quad
\lambda^* = -2.
\]
Since the dual constraint requires \(\lambda \ge 0\), the maximum occurs at the boundary:
\[
\lambda^* = 0.
\]
Thus:
\[
g(0) = 0.
\]
- **Primal optimum**:
\[
\min_{x \le 1} x^2 \quad \Rightarrow \quad x^* = 0, \quad f(x^*) = 0.
\]
- **Dual optimum**:
\[
\max_{\lambda \ge 0} g(\lambda) = 0.
\]
Therefore,
\[
f^* = g^* = 0
\]
</div>
<div class="example">
Consider the linear program
\[
\begin{aligned}
\text{maximize } \quad & P = 3x + 5y \\
\text{subject to } \quad
& 2x + y \le 20, \\
& x + 2y \le 12, \\
& x + 3y \le 15, \\
& x \ge 0,\; y \ge 0.
\end{aligned}
\]
Solve the problem, reformulate the problem using matrices, find the dual problem.
Since this is a linear program in two variables, the optimum occurs at a **corner point** of the feasible region.
Corner points:
1. \( (0,0) \Longrightarrow P = 0 \)
2. \( (10,0) \Longrightarrow P = 3(10) = 30 \)
3. \( (0,4) \Longrightarrow P = 5(4) = 20 \)
4. \( (6,3) \Longrightarrow P = 3(6) + 5(3) = 33 \)
\[
(x^*, y^*) = (6,3), \quad P^* = 33
\]
---
**Matrix Form of the Primal Problem**
Let
\[
\mathbf{x} =
\begin{bmatrix}
x \\ y
\end{bmatrix},
\quad
\mathbf{c} =
\begin{bmatrix}
3 \\ 5
\end{bmatrix},
\quad
\mathbf{b} =
\begin{bmatrix}
20 \\ 12 \\ 15
\end{bmatrix},
\]
\[
\mathbf{A} =
\begin{bmatrix}
2 & 1 \\
1 & 2 \\
1 & 3
\end{bmatrix}.
\]
Then the primal problem is
\[
\begin{aligned}
\max_{\mathbf{x}} \quad & \mathbf{c}^\top \mathbf{x} \\
\text{subject to } \quad & \mathbf{A}\mathbf{x} \le \mathbf{b}, \\
& \mathbf{x} \ge 0.
\end{aligned}
\]
For the dual problem, we introduce Lagrange multipliers
\[
\boldsymbol{\lambda} =
\begin{bmatrix}
\lambda_1 \\ \lambda_2 \\ \lambda_3
\end{bmatrix}
\ge 0
\]
for the inequality constraints. For a primal maximization problem with \( \le \) constraints and \( \mathbf{x} \ge 0 \), the dual is a minimization problem:
\[
\begin{aligned}
\min_{\boldsymbol{\lambda}} \quad
& \mathbf{b}^\top \boldsymbol{\lambda}
= 20\lambda_1 + 12\lambda_2 + 15\lambda_3 \\
\text{subject to } \quad
& \mathbf{A}^\top \boldsymbol{\lambda} \ge \mathbf{c}, \\
& \boldsymbol{\lambda} \ge 0.
\end{aligned}
\]
That is,
\[
\begin{aligned}
\min \quad & 20\lambda_1 + 12\lambda_2 + 15\lambda_3 \\
\text{subject to } \quad
& 2\lambda_1 + \lambda_2 + \lambda_3 \ge 3, \\
& \lambda_1 + 2\lambda_2 + 3\lambda_3 \ge 5, \\
& \lambda_1, \lambda_2, \lambda_3 \ge 0.
\end{aligned}
\]
- Primal optimal value: \( P^* = 33 \)
- Dual optimal value: \( D^* = 33 \)
This confirms **strong duality** for this linear program.
</div>
---
#### Weak Duality and the Minimax Inequality
The **minimax inequality** is given in the following theorem. F
<div class="theorem">
For any function with two arguments $\phi(\mathbf{x}, \mathbf{y})$, the maximin is less than the minimax. That is,
\[
\max_{\mathbf{y}} \min_{\mathbf{x}} \phi(\mathbf{x}, \mathbf{y}) \le \min_{x}\mathbf{x} \max_{\mathbf{y}} \phi(\mathbf{x}, \mathbf{y})
\]
</div>
Using this, we derive **weak duality**.
<div class="theorem">
The optimal value of the dual problem is always less than or equal to the optimal value of the primal problem:
\[
\min_{\mathbf{x}} \max_{\mathbf{\mathbf{\lambda}} \ge 0} L(\mathbf{x}, \mathbf{\mathbf{\lambda}})
\ge
\max_{\mathbf{\mathbf{\lambda}} \ge 0} \min_{\mathbf{x}} L(\mathbf{x}, \mathbf{\mathbf{\lambda}})
\]
</div>
Thus, duality provides a lower bound on the primal problem’s optimal value.
---
#### Equality Constraints
If equality constraints are present, such as \( h_j(\mathbf{x}) = 0 \), they can be rewritten as two inequalities:
\[
h_j(\mathbf{x}) \le 0 \quad \text{and} \quad h_j(\mathbf{x}) \ge 0
\]
The associated Lagrange multipliers for equality constraints are **unconstrained**, while those for inequality constraints remain **non-negative**.
---
### Exercises {.unnumbered .unlisted}
<div class="exercise">
Find the maximum and minimum values of $f\left( {x,y} \right) = 81{x^2} + {y^2}$ subject to the constraint $4{x^2} + {y^2} = 9$.
<div style="text-align: right;">
[Solution]( )
</div>
</div>
<div class="exercise">
Find the maximum and minimum values of $f\left( {x,y} \right) = 8{x^2} - 2y$ subject to the constraint ${x^2} + {y^2} = 1$.
<div style="text-align: right;">
[Solution]( )
</div>
</div>
<div class="exercise">
Find the maximum and minimum values of $f\left( {x,y,z} \right) = {y^2} - 10z$ subject to the constraint ${x^2} + {y^2} + {z^2} = 36$.
<div style="text-align: right;">
[Solution]( )
</div>
</div>
<div class="exercise">
Find the maximum and minimum values of $f\left( {x,y,z} \right) = xyz$ subject to the constraint $x + 9{y^2} + {z^2} = 4$. Assume $x \geq 0$ for this problem. Why is this needed?
<div style="text-align: right;">
[Solution]( )
</div>
</div>